4

I've run into a peculiar situation where I am trying to find any geospatial objects that lie (partially) in a polygon. When I apply the ST_Intersect function on two Geometries using the WGS84 SRID the intersection of a polygon and a point clearly North of the polygon returns FALSE as expected:

SELECT ST_Intersects(
    ST_GeomFromText('POLYGON((-12 0,12 0,12 50.7,-12 50.7,-12 0))', 4326), 
    ST_GeomFromText('POINT(6.0 50.9)', 4326)
);


Now when I run this same query, but with two geographies instead of geometries the query returns TRUE:

SELECT ST_Intersects( 
    ST_GeogFromText('POLYGON((-12 0,12 0,12 50.7,-12 50.7,-12 0))'),
    ST_GeogFromText('POINT(6 50.9)')
);

I expect that the geography version uses shortest great circle distance to create the polygon, while the geometry version creates the polygon on a flat plane and only then projects this on the WGS84 ellipse.

Can someone verify or debunk my suspicions?

I am running postgresql 9.6 with PostGis 2.4.4

JGH
  • 15,928
  • 4
  • 31
  • 48

1 Answers1

2

Operations on geography data type are done over a sphere. Operations on geometry data type are done over a plane.

The shortest line joining two points on a plane is a straight line.

The shortest line joining two points on a sphere is an arc. This arc is called the great circle arc and is build by intersecting the sphere with a plan going through the 2 points and the center of the earth.

Consequently, the arc going through -12;50.7N and +12;50.7N with pass through a point near 0;51.3N. This holds true for lines but also for polygon boundaries.

This doc has some interesting graphics to understand the concepts behind the geography type

JGH
  • 15,928
  • 4
  • 31
  • 48