I am new to osm. Currently I am trying to retrieve multiple cities' building polygon using osmnx package in python.
Code:
place = "Kuala Lumpur, Malaysia"
graph = ox.footprints.footprints_from_place(place, footprint_type='building')
graph.head()
It works fine.
However, if I want to get another state, it returns an error.
(also the same result if I want to retrieve it at country level - in this case - place = "Malaysia")
place = "Selangor, Malaysia"
graph = ox.footprints.footprints_from_place(place, footprint_type='building')
graph.head()
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-20-9e3439b6fc4c> in <module>()
1 place = "Selangor, Malaysia"
----> 2 graph = ox.footprints.footprints_from_place(place, footprint_type='building')
3
4 graph.head()
5 frames
/usr/local/lib/python3.6/dist-packages/shapely/geometry/multipolygon.py in geos_multipolygon_from_polygons(arg)
175 # no implicit flattening.
176 if isinstance(obs[0], MultiPolygon):
--> 177 raise ValueError("Sequences of multi-polygons are not valid arguments")
178
179 exemplar = obs[0]
ValueError: Sequences of multi-polygons are not valid arguments
Can someone help me? Thanks
It looks like OSMnx's footprints
module is not correctly handling or disregarding a complex (and possibly invalid?) multipolygon geometry. Note that efforts are underway to replace the footprints
and pois
modules with a more powerful, robust, generalizable geometries
module. In the meantime, I believe you can accomplish your goal with the pois
module like this:
import osmnx as ox
ox.config(use_cache=True, log_console=True)
place = 'Selangor, Malaysia'
gdf = ox.pois_from_place(place, tags={'building': True})
gdf.shape # (47516, 390)