In PostGIS, a polygon that is more than half the world is considered the opposite.

I am using GeoDjango with PostGIS and am trying to use a polygon to get records from a database that fall inside it.

If I define a polygon that is more than half the area of โ€‹โ€‹the earth, it assumes that the โ€œinsideโ€ of my polygon is the smaller area that I intended to โ€œoutsideโ€ and returns only results that are outside of it.

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

Update: If 180 degrees longitude is inside my polygon, this does not work at all. GEOS seems to be to blame this time. This image shows what I consider the reason. Green is the polygon that I define, Red is how it interprets it. Polygons on earth Again, this seems like a problem that often arises and one of those with libraries like GEOS related to. Is there any way?

+6
source share
1 answer

Ok, no answers. Here is what I did.

Since GEOS does not like things crossing the 180th meridian:
First check if the polygon crosses the 180th meridian. If so, divide it into 2 polygons along this line.

Since PostGIS assumes that the polygon is as small as possible, you cannot make one cover for more than half the world, therefore:
Make sure the polygon or each of the divided polygons covers half the world or more. If so, divide them in half.

Create a MultiPolygon from the results.

+5
source

Source: https://habr.com/ru/post/886342/


All Articles