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



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

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

代码

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)

并转换为geodataframe:

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

最新更新