PostGIS - 某些MultiPolygons导致“BOOM!无法生成外部点!”

时间:2011-05-03 00:26:15

标签: postgis geodjango geos

我试图表示一个经过180度经度的矩形区域。有关更多背景信息,请参阅In PostGIS a polygon bigger than half the world is treated as it's opposite

这是我的测试用例:

from django.contrib.gis.geos import Polygon, MultiPolygon
from my_project.my_app.models import Photo

a = Polygon.from_bbox((30, -80, 180, 80))  # the part to the east of 180
b = Polygon.from_bbox((-180, -80, -160, 80))  # a part to the west of 180
c = Polygon.from_bbox((-180, -80, -100, 80))  # a larger part to the west of 180

ok   = MultiPolygon(a,b)
ok2  = MultiPolygon(c)
boom = MultiPolygon(a,c)

# This works
Photo.objects.filter(location__coveredby=ok)[:1]
# This also works so c is ok
Photo.objects.filter(location__coveredby=ok2)[:1]
# This gives "BOOM! Could not generate outside point!"
Photo.objects.filter(location__coveredby=boom)[:1]

# splitting c doesn't help
c1 = Polygon.from_bbox((-180, -80, -140, 80))
c2 = Polygon.from_bbox((-140, -80, -100, 80))
test = MultiPolygon(a,c1,c2)
Photo.objects.filter(location__coveredby=test)[:1]
# BOOM! Could not generate outside point!

通过更改数字,我可以使此错误来来去去。 (-180,-80,x,80)在x <= -140的情况下工作。对于每个数字都有这样的阈值,但我找不到模式。对于具有相同区域的盒子,有些可以使用,有些则不可用。对于宽度相同的盒子,有些可以使用,有些则不可用。

我可以查看正在生成的SQL,但区域以二进制表示(EWKB),我不知道如何阅读它。

任何人都能解释一下吗?

1 个答案:

答案 0 :(得分:1)

在问了这个问题后,我发现了gis.stackexchange.com,所以我也在那里问过。在好人们的帮助下,我发现了问题(我认为)和解决方案。

请参阅: https://gis.stackexchange.com/questions/9217/postgis-certain-multipolygons-cause-boom-could-not-generate-outside-point/9257#9257