Skip to content
Advertisement

Data from OSM (overpy) to geodataframe with polygons

I try to put OSM data (some polygons) to geodataframe. Export from OSM contains LineString. But in the end i need to converte all data into geodataframe in this format:

0 -> name_from_tag_first_area -> polygon (or multipolygon) type with coordinates

1 -> name_from_tag_second_area -> polygon (or multipolygon) type with coordinates

And then i will use this GeoDataFrame to visualize this polygons.

JavaScript

wrong result

In my dataframe not a polygon – only GeometryCollection with LineString. Please could you explain how I can do this task?

Advertisement

Answer

Apart from an additional import I will keep the beginning of your script as the same.

JavaScript

Your GeoDataFrame contains GeoJSON Geometries. In the first step the geometries have to be converted to shapely geometries with the shape function. After that we convert the GeometryCollections to Polygons with the polygonize function.

JavaScript

Now you can convert your results_dict into a GeoDataFrame. Note that a boundary could be multiple Polygons. Maybe you want each Polygon to has it’s own row. For this you can use the explode function.

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement