从GeoJSON对象

时间:2016-06-09 14:17:21

标签: gis geojson geopandas

我有一个多边形的特征集,我必须首先将它写在一个临时文件中然后用geopandas.GeoDataFrame.from_file(tmp_json_file)加载它,有没有办法不写临时文件并只创建{{1来自GeoDataFrame对象?

1 个答案:

答案 0 :(得分:10)

您可以使用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)