Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/transit stops osm #72

Merged
merged 9 commits into from
Sep 11, 2024
26 changes: 15 additions & 11 deletions city_metrix/layers/open_street_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ class OpenStreetMapClass(Enum):
'amenity': ['school', 'kindergarten']}
HIGHER_EDUCATION = {'amenity': ['college', 'university'],
'building': ['college', 'university']}
TRANSIT_STOP = {'amenity':['ferry_terminal'],
'railway':['stop', 'platform', 'halt', 'tram_stop', 'subway_entrance', 'station'],
'highway':['bus_stop', 'platform'],
'public_transport': ['platform', 'stop_position', 'stop_area'],
'station':['subway'],
'aerialway':['station']}


class OpenStreetMap(Layer):
Expand All @@ -44,11 +50,16 @@ def get_data(self, bbox):
osm_feature = gpd.GeoDataFrame(pd.DataFrame(columns=['osmid', 'geometry']+list(self.osm_class.value.keys())), geometry='geometry')
osm_feature.crs = "EPSG:4326"

# Filter out Point and LineString (if the feature is not ROAD)
if self.osm_class != OpenStreetMapClass.ROAD:
osm_feature = osm_feature[osm_feature.geom_type.isin(['Polygon', 'MultiPolygon'])]
else:
# Filter by geo_type
if self.osm_class == OpenStreetMapClass.ROAD:
# Filter out Point
osm_feature = osm_feature[osm_feature.geom_type != 'Point']
elif self.osm_class == OpenStreetMapClass.TRANSIT_STOP:
# Keep Point
osm_feature = osm_feature[osm_feature.geom_type == 'Point']
else:
# Filter out Point and LineString
osm_feature = osm_feature[osm_feature.geom_type.isin(['Polygon', 'MultiPolygon'])]

# keep only columns desired to reduce file size
keep_col = ['osmid', 'geometry']
Expand All @@ -61,10 +72,3 @@ def get_data(self, bbox):
osm_feature = osm_feature.reset_index()[keep_col]

return osm_feature

def write(self, output_path):
self.data['bbox'] = str(self.data.total_bounds)
self.data['osm_class'] = str(self.osm_class.value)

# Write to a GeoJSON file
self.data.to_file(output_path, driver='GeoJSON')