2017-04-14 14 views
0

でエラーが発生私はOpenTripPlannerで生成アイソクロンポリゴンを有する:OpenTripPlannerで生成された空のポリゴン.is_empty格好の良い命令

{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"MultiPolygon","coordinates":[]},"properties":{"time":-47},"id":"fid--576b228b_15b66d32d71_-7cbd"}]} 

この多角形は、以下の指示に格好の良いオブジェクトとして翻訳される:

isochrone = shapely.geometry.asShape(isochroneJSON['features'][0]['geometry']) 

{u'type': u'FeatureCollection', u'features': [{u'geometry': {u'type': u'MultiPolygon', u'coordinates': []}, u'type': u'Feature', u'properties': {u'time': -47}, u'id': u'fid--576b228b_15b66d32d71_-7a54'}]} 

I:

これは、スパイダーでどのように見えるかです本当に私には空のポリゴンのように見えます。私の問題は、それを他の治療法から除外し、それが有効であるか空であるかをチェックすることです。そして、次の命令:

return (self._geom is None) or bool(self.impl['is_empty'](self)) 
self.__geom__, n = self.factory(self.context) 

the only similar questionは私自身の問題を持っていないように見えるので、私は完全に失われています:

if not isochrone.is_empty: 

は.is_emptyすっきり命令でエラーを生成します。

答えて

1

空のジオメトリは、あなたの特定のケース(マルチポリゴン)で、あなたが部分的にshape代わりのasShapeを使用して、それを修正することができ、少しトリッキーです:

import json 
from shapely.geometry import MultiPolygon, shape, mapping, asShape 

Q = shape({'type': 'MultiPolygon', 'coordinates': []}) 
print(Q.is_empty) 
print(Q.geom_type) 
print(json.dumps(mapping(Q))) 

この出力(geom_typeが空のマルチポリゴンの場合であり、実際にはMultiPolygonと等しくない):

True 
GeometryCollection 
{"type": "MultiPolygon", "coordinates": []} 
+0

私の場合、 'asShape'の代わりに 'shape'を使用するだけでエラーが取り除かれました。しかし、なぜ私に尋ねないでください! –

関連する問題