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

Gis 如何使用多边形(shapefile)作为边界框从OSM下载建筑物数据?,gis,openstreetmap,geopandas,osmnx,Gis,Openstreetmap,Geopandas,Osmnx,我正在努力完成这项任务。我正在尝试OSMnx,它可以用来从上面的OSM下载数据,但是我在尝试下载数据时使用它的from_polygon功能时出错。此外,我不确定这些数据是否包括建筑物数据 我将shapefile加载到geopandas中,然后可以查看并与之交互 这是密码 Building_data = ox.graph_from_polygon(my_shapefile, network_type='all') ox.plot_graph(Building_data) 然而,我得到了这个错误

我正在努力完成这项任务。我正在尝试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')
但是,即使我将shapefile与OSMnx一起使用,我仍然会遇到以下错误:

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))

有什么想法吗?

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

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()

graph\u from\u polygon()
中的第一个参数应该是一个
shapely polygon
,而不是整个shapefile。我设法将shapefile更改为一个shapely polygon并再次运行OSMnx脚本,但是现在我得到了这个错误:无效投影:+proj=utm+zone=80957+ellps=WGS84+datum=WGS84+units=m+no\u defs+type=crs:(内部项目错误:项目创建:错误-35(无效的UTM区号))。有任何建议@swatchai?显示您当前的代码。没有它,没有人能有效地帮助您。@swatchai我编辑了原始帖子,谢谢!多边形必须使用坐标:lat,long;以度为单位。参考:
帮助(ox.graph\u from\u polygon)