开发者

In PostGIS a polygon bigger than half the world is treated as it's opposite

I'm using GeoDjango with PostGIS and trying to use a polygon to get records from a database which fall inside it.

If I define a polygon which is bigger than half the area of the earth it assumes the 'inside' of my polygon is the smaller area which I intended as the '开发者_运维技巧outside' and returns only results which are outside it.

I can just use this smaller, wrong area to exclude results. Polygon.area seems to know what I intend so I can use this to determine when to make my search inclusive or exclusive. I feel like this problem is probably common, is there a better way to solve it?

Update: If 180 degrees longitude is inside my polygon this doesn't work at all. It seems GEOS is to blame this time. This image shows what I believe is the reason. Green is the polygon I define, Red is how it seems to be interpreting it.

In PostGIS a polygon bigger than half the world is treated as it's opposite

Again this seems like a problem which would crop up often and one that libraries like GEOS are made to deal with. Is there a way?


Alright, no answers. Here's what I've done.

Because GEOS doesn't like things crossing the 180th meridian:
First check if the polygon crosses the 180th meridian - If so, break it into 2 polygons along that line.

Because PostGIS assumes a polygon is as small as possible you can't make one cover more than half the world, so:
Check if the polygon or each of the split polygons covers half the world or more - If so, break them in half.

Construct a MultiPolygon from the results.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜