Forum OSM France

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.

import overpy
import requests
import json
import geopandas as gpd

from shapely.geometry import shape

url = "https://maps.mail.ru/osm/tools/overpass/api/interpreter"
query = """[out:json];
area['boundary' = 'administrative']['name' = 'Москва'] -> .MSK;
(
relation(area.MSK)['admin_level' = 8]['boundary' = 'administrative']['name'='Бескудниковский район'];
relation(area.MSK)['admin_level' = 8]['boundary' = 'administrative']['name'='район Восточное Дегунино'];
);
convert item ::=::,::geom=geom(),_osm_type=type();
out geom;"""
response = requests.get(url, params={'data': query})
data = response.json()

geo_df = gpd.GeoDataFrame(data['elements'])

wrong result: https://i.stack.imgur.com/J2J85offset-smoker-in-1000-dollar

In my dataframe not a polygons - only geometrycollection with LineString. Please could you explain how I can do this taskю Thanks.

2 posts - 2 participants

Read full topic


Ce sujet de discussion accompagne la publication sur https://community.openstreetmap.org/t/data-from-osm-overpy-to-geodataframe-with-polygons/1738