首页 > 解决方案 > OSMnx:检索多个城市的建筑多边形

问题描述

我是osm的新手。目前我正在尝试使用 python 中的 osmnx 包检索多个城市的建筑多边形。

代码:

place = "Kuala Lumpur, Malaysia"
graph = ox.footprints.footprints_from_place(place, footprint_type='building')

graph.head()

它工作正常。

但是,如果我想获得另一个状态,它会返回一个错误。

(如果我想在国家一级检索它,结果也是一样的 - 在这种情况下 - 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

有人能帮我吗?谢谢

标签: pythonpolygonopenstreetmapvalueerrorosmnx

解决方案


看起来 OSMnx 的footprints模块没有正确处理或忽略复杂的(并且可能无效?)多面几何。请注意,我们正在努力用更强大、更健壮、更通用的模块替换footprints和模块。同时,我相信您可以通过以下模块实现您的目标:poisgeometriespois

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)

推荐阅读