Thursday 25 February 2016

postgresql - PostGIS: incorrect interpretation of a polygon that intersects the 180th meridian


I try to find out all geopoints which intersect the polygon set as a parameter.


The problem is when I pass polygon that roughly covers an area of Bering Strait (nearby 180 longitude): enter image description here


So I use the query:


SELECT ST_AsText(l.geo_point)
FROM "lightnings" "l"
WHERE (ST_Intersects(ST_GeomFromText('Polygon((132.0 40.0, -148.0 40.0, -148.0 -8.0, 132.0 -8.0, 132.0 40.0) )', 4326), geo_point));


As you can see, vertexes are set in a correct order, clockwise, from the North-West. But the result covers outside area and including whole other world.


For example, in result:


POINT(75.5637 40.0434)

The problem doesn't touch the 0th meridian.


Elementary test:


SELECT ST_Area(ST_GeomFromText('Polygon((0.0 60.0, 10.0 60.0, 10.0 40.0, 0.0 40.0, 0.0 60.0) )', 4326))
UNION ALL
SELECT ST_Area(ST_GeomFromText('Polygon((-5.0 60.0, 5.0 60.0, 5.0 40.0, -5.0 40.0, -5.0 60.0) )', 4326))

UNION ALL
SELECT ST_Area(ST_GeomFromText('Polygon((175.0 60.0, -175.0 60.0, -175.0 40.0, 175.0 40.0, 175.0 60.0) )', 4326))

gives the result:


200
200
7000

Is there any simple trick to force PostGIS understanding me? I don't like an idea to divide the polygon...




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...