From 12e9c2119ccfef7243a3cefe78b66b1cdbdbbfd3 Mon Sep 17 00:00:00 2001 From: weiqi-tori Date: Mon, 23 Dec 2024 11:45:26 +0800 Subject: [PATCH] fix osm column name and tags issue --- city_metrix/layers/open_street_map.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/city_metrix/layers/open_street_map.py b/city_metrix/layers/open_street_map.py index 6a8c99d..af0455d 100644 --- a/city_metrix/layers/open_street_map.py +++ b/city_metrix/layers/open_street_map.py @@ -7,6 +7,13 @@ class OpenStreetMapClass(Enum): + # ALL includes all 29 primary features https://wiki.openstreetmap.org/wiki/Map_features + ALL = {'aerialway': True, 'aeroway': True, 'amenity': True, 'barrier': True, 'boundary': True, + 'building': True, 'craft': True, 'emergency': True, 'geological': True, 'healthcare': True, + 'highway': True, 'historic': True, 'landuse': True, 'leisure': True, 'man_made': True, + 'military': True, 'natural': True, 'office': True, 'place': True, 'power': True, + 'public_transport': True, 'railway': True, 'route': True, 'shop': True, 'sport': True, + 'telecom': True, 'tourism': True, 'water': True, 'waterway': True} OPEN_SPACE = {'leisure': ['park', 'nature_reserve', 'common', 'playground', 'pitch', 'track'], 'boundary': ['protected_area', 'national_park']} OPEN_SPACE_HEAT = {'leisure': ['park', 'nature_reserve', 'common', 'playground', 'pitch', 'garden', 'golf_course', 'dog_park', 'recreation_ground', 'disc_golf_course'], @@ -23,7 +30,7 @@ class OpenStreetMapClass(Enum): 'building': ['office', 'commercial', 'industrial', 'retail', 'supermarket'], 'shop': True} SCHOOLS = {'building': ['school',], - 'amenity': ['school', 'kindergarten']} + 'amenity': ['school', 'kindergarten']} HIGHER_EDUCATION = {'amenity': ['college', 'university'], 'building': ['college', 'university']} TRANSIT_STOP = {'amenity':['ferry_terminal'], @@ -35,7 +42,7 @@ class OpenStreetMapClass(Enum): class OpenStreetMap(Layer): - def __init__(self, osm_class=None, **kwargs): + def __init__(self, osm_class=OpenStreetMapClass.ALL, **kwargs): super().__init__(**kwargs) self.osm_class = osm_class @@ -47,7 +54,7 @@ def get_data(self, bbox): osm_feature = ox.features_from_bbox(bbox=(left, bottom, right, top), tags=self.osm_class.value) # When no feature in bbox, return an empty gdf except ox._errors.InsufficientResponseError as e: - osm_feature = gpd.GeoDataFrame(pd.DataFrame(columns=['osmid', 'geometry']+list(self.osm_class.value.keys())), geometry='geometry') + osm_feature = gpd.GeoDataFrame(pd.DataFrame(columns=['id', 'geometry']+list(self.osm_class.value.keys())), geometry='geometry') osm_feature.crs = "EPSG:4326" # Filter by geo_type @@ -62,7 +69,7 @@ def get_data(self, bbox): osm_feature = osm_feature[osm_feature.geom_type.isin(['Polygon', 'MultiPolygon'])] # keep only columns desired to reduce file size - keep_col = ['osmid', 'geometry'] + keep_col = ['id', 'geometry'] for key in self.osm_class.value: if key in osm_feature.columns: keep_col.append(key)