2017-04-14 6 views
0

.is_empty 매끈한 명령으로 오류가 발생하는빈 다각형 내가 OpenTripPlanner으로 생성 된 아이소 다각형을

다각형은 다음 지시 매끈한 객체로 번역된다
{"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'를 사용하면 오류가 제거되었습니다. 그러나 나에게 묻지 마라!! –