2016-06-09 44 views
4

我有一個多邊形的功能集合,我必須先將它寫入臨時文件,然後用geopandas.GeoDataFrame.from_file(tmp_json_file)加載它,有沒有什麼辦法可以不寫臨時文件,來自GeoJSON對象的GeoDataFrame從GeoJSON對象創建一個GeoDataFrame

回答

9

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

它就像簡單的多邊形一個魅力,但我還有一個'FeatureColletion'組成Polygons'和'MultiPolygons'的'我不知道如何處理它的幾何形狀 – kwn

+0

「如何處理它的幾何形狀」是什麼意思?它是否無法創建geopandas GeoDataFrame? (因爲那些可以容納具有不同幾何類型的幾何列,所以這應該不成問題) – joris

+0

您能爲此打開一個單獨的問題嗎? (因爲這是別的,關於如何創建FeatureCollection) – joris