I am trying to find the point of intersection between a great cirle arc and a polygon. I am working in long/lat, where I am given the endpoints of the great circle arc, A and B, and the vertices, C, D, E and F of the polygon in long/lat. The point A is inside the polygon and point B is outside of the polygon. It is obvious by construction that the great circle arc intersects the polygon on the CD side of the polygon. When I compute the intersection of the great circle arc AB, represented by a LINESTRING, with the POLYGON CDEF, I get a LINESTRING from a point on CD to A; when I compute the intersection of the great circle arc AB with the LINESTRING CD, I get a different point on CD. Here are the details:
A: -122.3 47.4
B: -84.4 33.6
C: -107 49
D: -107 31
E: -130 31
F: -130 49
(1) intersect LINESTRING and POLYNOMIAL
select st_astext(st_intersection(st_geographyfromtext('linestring(-84.4 33.6, -122.3 47.4)'), st_geographyfromtext('polygon((-107 49, -107 31, -130 31, 130 49, -107 49))')));
====>
LINESTRING(-107 42.1770201452269, -122.3 47.3999999999286
(2) intersect LINESTRING and LINESTRING
select st_astext(st_intersection(st_geographyfromtext('linestring(-84.4 33.6, -122.3 47.4)'), st_geographyfromtext('LINESTRING(-107 49, -107 31)')));
====>
POINT(-107.040211660479 43.9998296744469)
As you can see, this point is not the same as the endpoing in the output of (1).
What is going on?
I am running PostgreSQL9.3.4 on x86_64-unknown-linux-gnu, compiled by gcc (Ubuntu 4.8.2-16ubuntu6) 4.8.2, 64-bit POSTGIS="2.1.2 r12389" GEOS="3.4.2-CAPI-1.8.2 r3921" PROJ="Rel. 4.8.0, 6 March 2012" GDAL="GDAL 1.10.1, released 2013/08/26" LIBXML="2.9.1" LIBJSON="UNKNOWN" RASTER
Finally, a colleague of mine computed the intersection of the two great cirlce arcs directly calling the Java version of GDAL/OGR and got -107 41.8290237496.