我是全新的(一周前)的OSMnx包和一个学期的学习Python /地理信息系统,所以请放心,假设我令人震惊的无知。
我的总体目标是了解更多关于如何在城市级别实现OSMnx以获取OpenStreetMap (OSM)数据的知识。我的次要任务是创建一些Python代码,该代码提取OSM数据,我可以使用这些数据作为城市地区内核密度估计的边界数据。
我的第一个目标是获得一个多边形形状文件的Amherst,MA,并保存到我的电脑。
tag_bound = {"boundary":"administrative","admin_level":7,"area":True}
amherst_bound = ox.geometries.geometries_from_place(place_name,tag_bound, which_result=None, buffer_dist=None)
type(amherst_bound)
# Check to make sure it looks reasonable by plotting it. See https://geoffboeing.com/2016/11/osmnx-python-street-networks/
ox.project_gdf(amherst_bound).plot()
_ = amherst_bound.axis('off')
# Save the file
amherst_bound.save_gdf_shapefile(filename= r"C:\Users\afhal\Dropbox\Arboriculture\PythonGIS\finalproject\testshape.shp")
代码的两个部分有一个错误:
() 29类型( r"C:\Users\afhal\Dropbox\Arboriculture\PythonGIS\finalproject\testshape.shp") ) 30 ox.project_gdf(amherst_bound).plot() -> 31 _= amherst_bound.axis('off') 32 33 amherst_bound.save_gdf_shapefile(filename= .plot)
C:\Users\afhal.conda\envs\OpenStreetMap\lib\site-packages\pandas\core\generic.py in getattr(self,name) 5137如果self._info_axis._can_hold_identifiers_and_holds_name(name):5138
返回自名object.getattribute(self,5139返回setattr(self,名称) 5140 5141 def setattr(self,名称:-> ) -> None:
AttributeError:“GeoDataFrame”对象没有属性“轴”
(仍然会产生这种情况,这看起来很奇怪:
)
() 31 r"C:\Users\afhal\Dropbox\Arboriculture\PythonGIS\finalproject\testshape.shp") = amherst_bound.axis('off') 32 -> 33 amherst_bound.save_gdf_shapefile(filename= filename= 34 35 ) ( C:\Users\afhal.conda\envs\OpenStreetMap\lib\site-packages\pandas\core\generic.py in getattr(self,name) 5137如果是self._info_axis._can_hold_identifiers_and_holds_name(name):5138 返回自名object.getattribute(self,5139返回setattr(self,名称) 5140 5141 def setattr(self,名称:-> ) -> None: AttributeError: GeoDataFrame对象没有属性“save_gdf_shapefile”
我一直看到人们使用DiGraphs而不是gdb (OSMnx:使用替代基础设施创建自定义查询和地图上的GeoPandas和OSMnx绘图),但我不知道为什么会喜欢这样做。
我的计划和储蓄哪里出错了?
发布于 2020-11-28 21:57:48
您的代码片段中有未定义的变量,因此它是不可复制的,但是我将尝试对您正在做的事情和目标做一些猜测。首先,如果您是OSMnx包的新手,请确保您有时间使用它的使用实例,因为它们演示了如何完成您想要做的所有事情。然后咨询文献资料以获得更多详细信息。当OSMnx允许您在NetworkX和Geopandas中使用OpenStreetMap数据时,请确保您也熟悉这些包。
我的第一个目标是获得一个多边形形状文件的Amherst,MA,并保存到我的电脑。
如果您想要Amherst的(多边形)管理边界,只需像示例和文档中所描述的那样,将该城市名称编码为GeoDataFrame。然后,您可以以普通的Geopandas方式将您的GeoDataFrame保存为一个shapefile:
import osmnx as ox
ox.config(use_cache=True, log_console=True)
gdf = ox.geocode_to_gdf('Amherst, MA')
gdf.to_file('amherst-shapefile')
如果你想要绘制你的GeoDataFrame:
ax = gdf.plot()
_ = ax.axis('off')
确保您阅读了(上面链接的)使用示例和文档,以便您知道如何使用OSMnx。如果您不熟悉Geopandas/NetworkX,请确保对这些包也这样做。
https://stackoverflow.com/questions/65052297
复制相似问题