I'm retrieving some geometries from OpenStreetMap with OSMnx library with the following code:
G = ox.graph_from_place('Casco Viejo, Bilbao, Spain', network_type='walk',
retain_all=True, buffer_dist = 50, which_result = 2,
infrastructure = 'relation["highway" = "pedestrian"]')
which yields the following graph composed by shapely linestrings:
Then I convert the graph into a geopandas geodataframe:
ped = ox.graph_to_gdfs(G, nodes = False)
I've tried this to convert Linestrings to Points and then Points to Multipolygon
Is there a way to convert this linestrings into a shapely Multipolygon:
from shapely import geometry, ops
combine them into a multi-linestring
multi_line = geometry.MultiLineString(list(ped['geometry']))
merged_line = ops.linemerge(multi_line)
from shapely.geometry import Point, MultiPoint
points = []
for i in range(0, len(merged_line)):
points.append((Point(list(merged_line[i].coords[1]))))
coords = [p.coords[:][0] for p in points]
poly = Polygon(coords)
This yields a weird wrong geometry:
shape(poly)
If I try:
MultiPolygon(points)
It gives this Error Message: TypeError: 'Point' object is not subscriptable
Is there a way to transform Linestrings into Multipolygon and this into GeoDataFrame?




