2016-06-10 8 views
0

에서 기능 모음을 만드는 데, 내가 찾고 있어요 임시 파일없이 그것을 할 수있는 방법. 나는 geopandas.GeoDataFrame.from_feature()을 사용하려고 시도했으나 단순한 다각형의 기능 모음에 대해서는 꽤 잘 작동했지만, Feature CollectionPolygonsMultiPolygons 인 경우 작동하지 못했습니다. 아래에서와 같이 생각하고 있었지만 아직 작동하지 않습니다.가 어떻게 <code>Polygons</code>과 <code>MultiPolygons</code>의 <code>Feature Collection</code>을하고 난 다음 geopandas.GeoDataFrame.from_file (tmp_json_file)와로드 먼저 임시 파일에 쓰기 위해 가지고 GeoJSON

features_collection = [] 

for feature in json_data['features']: 
    tmp_properties = {'id': feature['properties']['id']} 

    if is_multipolygon (feature): 
     tmp = Feature(geometry=MultiPolygon((feature['geometry']['coordinates'])), properties=tmp_properties) 
    else: 
     Feature(geometry=Polygon((feature['geometry']['coordinates'])), properties=tmp_properties) 
    features_collection.append(tmp) 

collection = FeatureCollection(features_collection) 

return geopandas.GeoDataFrame.from_features(collection['features']) 

GeoJSON은 영토를 반환하는 API에서 가져온 것입니다 (일부 지역은 다중의 형식 다각형의 집합()에 의해 다른 하나의 폴리곤에 의해 모델화된다.

GeoJSON에 따라로 구성되어 : http://pastebin.com/PPdMUGkY

나는 위의 함수에서 다음과 같은 오류를 받고 있어요

: 난 그냥 JSON을 공급하는 경우 나이를 위해

Traceback (most recent call last): 
    File "overlap.py", line 210, in <module> 
    print bdv_json_to_geodf(contours_bdv) 
    File "overlap.py", line 148, in json_to_geodf 
    return geopandas.GeoDataFrame.from_features(collection['features']) 
    File "/Library/Python/2.7/site-packages/geopandas/geodataframe.py", line 179, in from_features 
    d = {'geometry': shape(f['geometry'])} 
    File "/Library/Frameworks/GEOS.framework/Versions/3/Python/2.7/site-packages/shapely/geometry/geo.py", line 40, in shape 
    return MultiPolygon(ob["coordinates"], context_type='geojson') 
    File "/Library/Frameworks/GEOS.framework/Versions/3/Python/2.7/site-packages/shapely/geometry/multipolygon.py", line 64, in __init__ 
    self._geom, self._ndim = geos_multipolygon_from_py(polygons) 
    File "/Library/Frameworks/GEOS.framework/Versions/3/Python/2.7/site-packages/shapely/geometry/multipolygon.py", line 138, in geos_multipolygon_from_py 
    N = len(ob[0][0][0]) 
TypeError: object of type 'float' has no len() 
+0

재현 가능한 예를 제공하십시오 (http://stackoverflow.com/help/mcve). 'json_data '란 무엇입니까? 이미 FeatureCollection 인 경우 FeatureCollection을 만드는 이유는 무엇입니까? GeoDataFrame.from_features'에 제공하면 어떤 오류가 발생합니까? – joris

+0

예, 내 게시물을 편집했습니다. – kwn

답변

2

작동 _data 기능 GeoDataFrame.from_features에 :

In [17]: gdf = geopandas.GeoDataFrame.from_features(json_data['features']) 

In [18]: gdf.head() 
Out[18]: 
              geometry id 
0 (POLYGON ((-0.58570861816406 44.810461337462, ... 2 
1 (POLYGON ((-0.5851936340332 44.816550206151, -... 1 
2 POLYGON ((-0.58805465698242 44.824018340447, -... 5 
3 POLYGON ((-0.59412002563477 44.821664359038, -... 9 
4 (POLYGON ((-0.58502197265625 44.817159057661, ... 12 

생성 GeoDataFrame 입력 데이터처럼 다각형 W 다중의 혼합물을 가지고

In [19]: gdf.geom_type.head() 
Out[19]: 
0 MultiPolygon 
1 MultiPolygon 
2   Polygon 
3   Polygon 
4 MultiPolygon 
dtype: object 

I는 GeoPandas 0.2으로 매끈한 1.5.15 이것을 시도 0.18 판다. Windows에서 1.