【发布时间】:2021-05-11 00:43:38
【问题描述】:
我正在努力完成这项任务。我正在尝试 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))
有什么想法吗?
【问题讨论】:
-
graph_from_polygon()中的第一个参数应该是shapely Polygon,而不是整个 shapefile。 -
我设法将 shapefile 更改为一个匀称的多边形并再次运行 OSMnx 脚本,但是现在我收到此错误 CRSError: Invalid projection: +proj=utm +zone=80957 +ellps=WGS84 +datum =WGS84 +units=m +no_defs +type=crs:(内部项目错误:proj_create:错误 -35(无效的 UTM 区域编号))。 @swatchai 有什么建议吗?
-
显示您当前的代码。没有它,任何人都无法有效地提供帮助。
-
@swatchai 我编辑了原帖,谢谢!
-
polygon必须使用坐标:lat,long;以度为单位。参考:help(ox.graph_from_polygon)
标签: gis openstreetmap geopandas osmnx