与OpenTripPlanner产生空白的多边形产生误差.is_empty匀称指令

问题描述:

我有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']) 

这是怎么看起来像Spyder的:

{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'}]} 

我对我来说真的看起来像一个空的多边形。我的问题是,我想从我的其他治疗中排除它,并检查它是否有效和/或空。而下面的指令:

if not isochrone.is_empty: 

产生一个错误,与.is_empty匀称的指令:

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

而且我完全失去了,因为the only similar question似乎不会有我自己的问题。

空几何形状有点棘手,你的具体情况(MultiPolygons),可以部分地通过使用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'已经消除了错误。但不要问我为什么! –