Skip to content

Commit

Permalink
Merge pull request #654 from gboeing/geoms
Browse files Browse the repository at this point in the history
handle more relation types in geometries module and multi-index gdf
  • Loading branch information
gboeing authored Feb 11, 2021
2 parents 77b2535 + 9b2a4ac commit 1909251
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions osmnx/geometries.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
Retrieve points of interest, building footprints, or any other objects from
OSM, including their geometries and attribute data, and construct a
GeoDataFrame of them.
GeoDataFrame of them. You can use this module to query for nodes, ways, and
relations (the latter of type "multipolygon" or "boundary" only) by passing a
dictionary of desired tags/values.
"""

import logging as lg
Expand Down Expand Up @@ -359,6 +361,9 @@ def _create_gdf(response_jsons, polygon, tags):
# Set to hold the unique IDs of elements that do not have tags
untagged_element_ids = set()

# identify which relation types to parse to (multi)polygons
relation_types = {"boundary", "multipolygon"}

# extract geometries from the downloaded osm data
for response_json in response_jsons:
# Parses the JSON of OSM nodes, ways and (multipolygon) relations
Expand Down Expand Up @@ -398,9 +403,9 @@ def _create_gdf(response_jsons, polygon, tags):

elif (
element["type"] == "relation"
and element.get("tags").get("type") == "multipolygon"
and element.get("tags").get("type") in relation_types
):
# Parse all multipolygon relations to multipolygons
# parse relations to (multi)polygons
multipolygon = _parse_relation_to_multipolygon(
element=element, geometries=geometries
)
Expand Down Expand Up @@ -982,9 +987,5 @@ def _filter_gdf_by_polygon_and_tags(gdf, polygon, tags):
# remove columns of all nulls (created by discarded component geometries)
gdf.dropna(axis="columns", how="all", inplace=True)

# reset the index keeping the unique ids
gdf.reset_index(inplace=True)
# rename the new 'index' column to 'unique_id'
gdf.rename(columns={"index": "unique_id"}, inplace=True)

return gdf
# multi-index gdf by element_type and osmid then return
return gdf.set_index(["element_type", "osmid"])

0 comments on commit 1909251

Please sign in to comment.