Using GeoDatabases and GeoDataframes#
[18]:
import footbridge as ft
# large dataset of US National Highway System roads
# https://hepgis-usdot.hub.arcgis.com/datasets/dce9f09392eb474c8ad8e6a78416279b_0
fc = ft.FeatureClass("NHS.gdb/National_Highway_System__NHS_")
f"{len(fc)} rows"
[18]:
'492005 rows'
[19]:
# Set the CRS when creating the Feature Dataset
fds = ft.FeatureDataset(crs="EPSG:4326")
fds.crs.name
[19]:
'WGS 84'
[20]:
# The FeatureDataset will enforce the CRS
fds["NHS"] = fc
[21]:
# Or create an empty FeatureDataset, which has no CRS by default
fds = ft.FeatureDataset()
type(fds.crs)
[21]:
NoneType
[22]:
# The FeatureDataset sets its CRS from the first FeatureClass added
fds["NHS"] = fc
fds.crs.name
[22]:
'WGS 84'
[23]:
# FeatureDatasets can be added to more than one GeoDatabase
gdb1 = ft.GeoDatabase()
gdb1["NHS_dataset1"] = fds
gdb2 = ft.GeoDatabase()
gdb2["NHS_dataset2"] = fds
print(gdb1.fds_dict)
print(gdb2.fds_dict)
print("Note that the same object has different names ^")
{'NHS_dataset1': <footbridge._core.FeatureDataset object at 0x7fa8cc268380>}
{'NHS_dataset2': <footbridge._core.FeatureDataset object at 0x7fa8cc268380>}
Note that the same object has different names ^
[24]:
# Adding to the FeatureDataset updates it in both GeoDatabases
gdb1["NHS_dataset1"]["NHS_2"] = fc
print(gdb1.fc_dict)
print(gdb2.fc_dict)
{'NHS': <footbridge._core.FeatureClass object at 0x7fa8087dac10>, 'NHS_2': <footbridge._core.FeatureClass object at 0x7fa8087dac10>}
{'NHS': <footbridge._core.FeatureClass object at 0x7fa8087dac10>, 'NHS_2': <footbridge._core.FeatureClass object at 0x7fa8087dac10>}
[25]:
# Adding a FeatureClass directly to a FeatureDataset places it in the FeatureDataset named None
gdb1["NHS_fc2"] = fc
print(gdb1.fds_dict[None].fc_names)
['NHS_fc2']
[26]:
# FeatureClasses can be accessed as dicts, a list of names, or as a list of objects:
gdb1.fc_dict
[26]:
{'NHS': <footbridge._core.FeatureClass at 0x7fa8087dac10>,
'NHS_2': <footbridge._core.FeatureClass at 0x7fa8087dac10>,
'NHS_fc2': <footbridge._core.FeatureClass at 0x7fa8087dac10>}
[27]:
gdb1.fc_names
[27]:
['NHS', 'NHS_2', 'NHS_fc2']
[28]:
gdb1.fcs
[28]:
[<footbridge._core.FeatureClass at 0x7fa8087dac10>,
<footbridge._core.FeatureClass at 0x7fa8087dac10>,
<footbridge._core.FeatureClass at 0x7fa8087dac10>]
[29]:
# Which allows for easy access to FeatureClass functionality
for fc in gdb1.fcs:
print(fc.crs.name)
WGS 84
WGS 84
WGS 84
[29]: