PostGIS – Understanding Geography, Geometry, Distance, and WKT in PostGIS

postgiswell-known-text

I'm trying to understand the data conversions that happen in PostGIS when calculating distances in SRID 4326.

Why is it that when I run on my marin_jobs points table:

select cast (the_geom as geography), the_geom from 
marin_jobs where blockid10 = '060411141001010' limit 1;

I get

the_geom      the_geom
geography     geometry
010100....    010100....

And the wkt output values are exactly the same?

I came to this question because when I run a distance query (see below for code) on two points in my dataset, if I don't use cast () as geography I get out degrees, just like the Boundless Geography tutorial said I would. http://postgis.net/workshops/postgis-intro/geography.html

But I don't understand how if the inputs are (seem to be anyway) exactly the same, the outputs are different. Or should I ask…are the outputs really different?

Does that mean that the value of 0.0616262566763201 degrees and 6007.875564598 meters are the same, but just in different units?

But this doesn't jive with what the Boundless Tutorial says,

"On a sphere, the size of one “degree square” is quite variable, becoming smaller as you move away from the equator. Think of the meridians (vertical lines) on the globe getting closer to each other as you go towards the poles. So, a distance of 121 degrees doesn’t mean anything. It is a nonsense number."

Any plain English claficiation would be really helpful. This is keeping me up at night.

Distance Queries:

select st_distance (
               (select the_geom from marin_jobs where blockid10 = '060411141001010' limit 1),
               (select the_geom from marin_jobs where blockid10 = '060411070005007' limit 1)
               );

output: 0.0616262566763201

select st_distance (
                (select cast (the_geom as geography) from marin_jobs where blockid10 = '060411141001010' limit 1),
                (select cast (the_geom as geography) from marin_jobs where blockid10 = '060411070005007' limit 1)
               );

output: 6007.875564598

Best Answer

The PostGIS manual explains well the difference between geometry and geography and why ST_Distance gives different results in chapter 4 http://postgis.net/docs/using_postgis_dbmanagement.html#PostGIS_Geography.

ST_Distance with geography type gives as a result the great circle length that follows the surface of the globe (actually WGS84 spheroid). ST_Distance with geometry makes distance calculations as if the globe were flat as in the image below. You can measure with a ruler that both Greenland and Africa are about 60 degrees wide but only by using geography based distance you can see that 60 degrees at the equator is 6668 km while at 80 degrees N it is only 1106 km. enter image description here