从GeoJSON对象创建GeoDataFrame [英] Create a GeoDataFrame from a GeoJSON object

查看:71
本文介绍了从GeoJSON对象创建GeoDataFrame的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多边形要素集合,我必须先将其写入一个临时文件中,然后再使用 geopandas.GeoDataFrame.from_file(tmp_json_file)进行加载,有什么方法可以不编写临时文件并仅从 GeoJSON 对象创建 GeoDataFrame ?

I have a Feature Collection of polygons and I have to first write it in a temporary file to then load it with geopandas.GeoDataFrame.from_file(tmp_json_file), is there any way to not write the temporary file and to just create the GeoDataFrame from the GeoJSON object ?

推荐答案

您可以为此使用 GeoDataFrame.from_features()函数.一个小例子(假设您有一个geojson FeatureCollection):

You can use the GeoDataFrame.from_features() function for this. A small example (supposing you have a 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)

这篇关于从GeoJSON对象创建GeoDataFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆