[postgis-users] Find polygon border crossings over dateline

Evan Martin postgresql at realityexists.net
Mon Feb 6 18:31:22 PST 2012


I have a table of polygons covering most of the world. I posted a 
question before about finding which of them are adjacent: 
http://postgis.refractions.net/pipermail/postgis-users/2012-January/031992.html 
Now I also have a set of great-circle lines (LINESTRINGs with only 2 
points) and I need to figure out which of them cross the border between 
two given polygons (in the right direction).

As before, there is often no precise "border" between the polygons - 
sometimes they overlap a little and sometimes there is a slight gap. So 
it's not just a matter of calling ST_Intersects(border_line, 
crossing_line). I tried 2 ways of doing this:

1) Buffer each polygon a bit to fill in the gaps, get the intersections 
and check if the line crosses that, ie.
ST_Intersects(ST_Intersection(ST_Buffer(polygon1, 100), 
ST_Buffer(polygon2, 100)), crossing_line)

2) Find ST_Intersection(polygon, crossing_line) for each polygon, which 
is a LINESTRING with 2 points. Where the end point of one of these 
LINESTRINGs is the start point of another that means crossing_line went 
from polygon1 to polygon2.

Both of these approaches seem to basically work - except when the shapes 
span the dateline. Doing the calculations on geometry doesn't return the 
right results, because the coordinates differ between shapes (eg. 190 
vs. -170). Doing them on geography fails with this error:

     ERROR:  Error performing intersection: TopologyException: found 
non-noded intersection between LINESTRING ...

I'm guessing that's because ST_Buffer and ST_Intersection on geography 
really work on geometry internally anyway.

Any ideas on how I can do this? Thanks in advance for any help!

Evan



More information about the postgis-users mailing list