如何使用多边形(shapefile)作为边界框从 OSM 下载建筑物数据?

How to download buildings data from OSM with a polygon (shapefile) as the bounding box?

我正在努力完成这项任务。我正在尝试 OSMnx,它可用于从上面的 OSM 下载数据,但是在尝试下载数据时使用其 from_polygon 功能时出现错误。此外,我不确定此数据是否包含建筑数据。

我将我的 shapefile 加载到 geopandas 中,然后可以查看它并与之交互

这是代码

Building_data = ox.graph_from_polygon(my_shapefile, network_type='all')
ox.plot_graph(Building_data)

但是我收到了这个错误

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

编辑:所以我尝试改用 OSMnx 库:

import osmnx as ox
import shapefile
import geopandas
from shapely.geometry import shape

shp = shapefile.Reader('shapefile.shp')
feature = shp.shapeRecords()[0]
first = feature.shape.__geo_interface__

#convert to shapely shape
shp_geom = shape(first)

fprints = ox.geometries.geometries_from_polygon(shp_geom, {'buildings':True})

fprints.to_file('footprints.shp', driver='ESRI Shapefile')

然而,即使我在 OSMnx 中使用 shapefile,我仍然收到错误:

CRSError: Invalid projection: +proj=utm +zone=80957 +ellps=WGS84 +datum=WGS84 +units=m +no_defs +type=crs: (Internal Proj Error: proj_create: Error -35 (invalid UTM zone number))

有什么想法吗?

我无法使用多边形(shapefile)作为边界框从 OSM 下载建筑物数据,但是我能够使用以下代码使用距某个点的距离:

import osmnx as ox 
import ast

point = 'point coordinates'
dist = 'distance in m'
buildings = ox.geometries.geometries_from_point(point, {'building': True}, dist=dist)

并转换为地理数据框:

buildings_save = buildings.applymap(lambda x: str(x) if isinstance(x, list) else x)

然后我使用 geopandas 将建筑物数据裁剪到边界:

import geopandas as gpd

boundary = gpd.read_file('C:/boundary.shp')
buildings_final = gpd.clip(buildings_save, boundary)

绘制要检查的数据:

import matplotlib.pyplot as plt

fig, ax = plt.subplots(figsize = (15,12))
buildings_final.plot(ax = ax, color = 'red', edgecolor = 'black',)
plt.title('Buildings Data')
plt.show()