OSMNx : 获取 polygons/buildings 的 nodes/corners/edges 的坐标

OSMNx : get coordinates of nodes/corners/edges of polygons/buildings

我正在尝试检索列表中每个商业建筑的所有 nodes/corners/edges 的坐标。例如。对于 Macclesfield(英国)的 Aldi 超市,我可以从 UI 10 个节点(超市的所有 corners/edges)中获取,但我只能从这 10 个节点中的 osmnx 2 中检索。我需要访问完整的节点列表,但它会截断结果,在此 case.Using 下面的代码中只给出 2 个 10 个节点:

import osmnx as ox

test = ox.geocode_to_gdf('aldi, Macclesfield, Cheshire, GB')
ax = ox.project_gdf(test).plot()
test.geometry

gdf = ox.geometries_from_place('Grosvenor, Macclesfield, Cheshire, GB', tags)
gdf.geometry

两个 return 只是两个坐标并截断 openStreetMap 中可用的其他 info/results UI(您可以在图像的第一列中看到它附加几何> POLYGON>仅两个坐标和其他结果被截断......)。在此先感谢您的帮助。

很难猜到你在这里做什么,因为你没有提供可重现的例子(例如,tags 是未定义的)。但我会试着猜猜你要做什么。

I am trying to retrieve the coordinates of all nodes/corners/edges of commercial buildings

在这里,我检索了麦克尔斯菲尔德所有标记的商业建筑足迹,然后提取第一个的多边形坐标。如果您只想要某些类型的建筑物,则可以根据您认为合适的其他属性值来过滤这些。 documentation.

中描述了 OSMnx 的 geometries 模块的正确用法
import osmnx as ox

# get the building footprints in Macclesfield
place = 'Macclesfield, Cheshire, England, UK'
tags = {'building': 'commercial'}
gdf = ox.geometries_from_place(place, tags)

# how many did we get?
print(gdf.shape)  # (57, 10)

# extract the coordinates for the first building's footprint
gdf.iloc[0]['geometry'].exterior.coords

或者,如果您想要特定建筑物的占地面积,您可以查找其 OSM ID 并告诉 OSMnx geocode 该值:

gdf = ox.geocode_to_gdf('W251154408', by_osmid=True)
polygon = gdf.iloc[0]['geometry']
polygon.exterior.coords
gdf = ox.geocode_to_gdf('W352332709', by_osmid=True)
polygon = gdf.iloc[0]['geometry']
polygon.exterior.coords
list(polygon.exterior.coords)