Skip to content

Commit

Permalink
fix osm column name and tags issue
Browse files Browse the repository at this point in the history
  • Loading branch information
weiqi-tori committed Dec 23, 2024
1 parent 13c78fb commit 12e9c21
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions city_metrix/layers/open_street_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -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'],
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 12e9c21

Please sign in to comment.