python - 从 GeoJSON 对象创建 GeoDataFrame

标签 python gis geojson geopandas

我有一个多边形特征集合,我必须首先将它写入一个临时文件中,然后用 geopandas.GeoDataFrame.from_file(tmp_json_file) 加载它。 , 有没有办法不写临时文件而只创建 GeoDataFrame来自 GeoJSON目的 ?

最佳答案

您可以使用 GeoDataFrame.from_features()为此功能。一个小例子(假设你有一个 geojson FeatureCollection):

In [1]: from geojson import Feature, Point, FeatureCollection

In [2]: my_feature = Feature(geometry=Point((1.6432, -19.123)), properties={"country": "Spain"})

In [3]: my_other_feature = Feature(geometry=Point((-80.234, -22.532)), properties={'country': 'Brazil'})

In [4]: collection = FeatureCollection([my_feature, my_other_feature])

In [6]: import geopandas

In [7]: geopandas.GeoDataFrame.from_features(collection['features'])
Out[7]:
  country                 geometry
0   Spain   POINT (1.6432 -19.123)
1  Brazil  POINT (-80.234 -22.532)

关于python - 从 GeoJSON 对象创建 GeoDataFrame,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37728540/

相关文章:

python - 如何解决?属性错误: 'NoneType' object has no attribute 'head'

Python 3.4 在生成部分(但不是全部)带有段错误 11 的 Cartopy map 时崩溃

php - 使用准备好的语句插入 GIS 几何图形

javascript - 每个标记有多个类别选项在传单 map 中使用 GeoJSON

python - 从 pySpark 中的 dict 构建一行

python - 根据列表从具有重复列的 DF 中选择行

maps - 将传单数据收集或geojson.io map 嵌入到表单中

javascript - 使用 CLUSTERS 时如何让 GeoJSON 属性出现在 openlayers 3 弹出窗口中?

python - 尝试通过 python-telegram-bot 发送照片时出现 UnicodeDecodeError

javascript - 将Web Mercator磁贴重新投影到D3的任意投影?