在使用cascaded_union(我也尝试了unary_union,但是出现了相同的错误)时,我遇到了以下错误:
ValueError: No Shapely geometry can be created from null value
我已经验证了我的多边形是有效的。 最初,polyB
是无效的,但使用 buffer(0)
转换为有效的多边形。
你有任何想法我做错了什么吗?以下是我的代码:
from shapely.geometry import Polygon
from shapely.ops import cascaded_union
def combineBorders(a, b):
polyA = Polygon(a)
polyB = Polygon(b)
pols = [polyA, polyB]
for p in pols:
if p.is_valid == False:
p = p.buffer(0)
print(p.is_valid)
True
True
newShape = cascaded_union(pols) # THIS IS WHERE THE ERROR KEEPS SHOWING UP
return newShape
这里有一个链接,其中包含polyA,polyB和pols的值(在确认它们有效后)。我在我的Ubuntu 14.04服务器上安装了以下版本:
- python-shapely 1.3.0
- libgeos 3.4.2
- python 2.7