0

我有一个用 OpenTripPlanner 生成的等时多边形:

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

使用以下指令将此多边形转换为 Shapely 对象:

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 shapely 指令生成错误:

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

我完全迷失了,因为唯一类似的问题似乎没有我自己的问题。

4

1 回答 1

1

空几何有点棘手,在您的特定情况下(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": []}
于 2017-04-18T10:17:32.573 回答