我很难将下面包含GIS数据(https://data.cityofnewyork.us/resource/5rqd-h5ci.json)的JSON加载到GeoDataFrame中。在
当我尝试设置几何体时,以下代码失败。在
import requests
import geopandas as gpd
data = requests.get("https://data.cityofnewyork.us/resource/5rqd-h5ci.json")
gdf = gpd.GeoDataFrame(data.json())
gdf = gdf.set_geometry('the_geom')
gdf.head()
使用从
pandas
和本机GeoDataFrame.from_features
继承的常规数据帧函数的一种更惯用的方法:对于使用web地图库的人。。。在
如果GeoJSON被包装在
FeatureCollection
中,就像web映射库(在我的例子中,是单张)导出到GeoJSON字符串时一样,那么您只需将位于features
的列表传递给from_features()
,如下所示:输出:
^{pr2}$别紧张。在
设置几何体失败,因为
geopandas.GeoDataFrame
构造函数似乎没有被构建为将JSON对象作为python数据结构来处理。因此,它抱怨参数不是有效的几何体对象。你必须把它解析成geopandas.GeoDataFrame
能理解的东西,比如shapely.geometry.shape
。以下是我这方面运行正常的Python 3.5.4:免责声明:我对Geo一无所知。直到我安装了
geopandas
来解决这个问题并阅读了一些在线文档之前,我甚至不知道这些库和这种数据的存在。在相关问题 更多 >
编程相关推荐