Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Geometry vs. Geography
Summary

Instruction

Great! Now, in order to determine what the distance would be if we instead used geometry columns, we need to learn how to convert a geography column to a geometry column.

Basically, all it takes is ::geometry after the column name, but you should also remember about choosing the right SRID.

SELECT 
  ST_Area(ST_Transform(
    boundaries::geometry, 3395))/1000000 
FROM usa_states 
WHERE name = 'Alaska';

As you can see, we used boundaries::geometry inside ST_Transform. Note that we had to change the SRID from 26910, which was true for San Francisco. The SRID of 3395 can be used for the whole world and has meters as its unit of length. We divided the result by a million to obtain the area of Alaska in square kilometers.

Exercise

Add a second column to the template and calculate the distance between the capitals of Florida and Alaska using geometry columns. Show both results in kilometers.

As you can see, the difference now is very serious. The distance calculated with the geometry column is roughly 37% greater than the real value.

Stuck? Here's a hint!

Use ST_Transform inside ST_Distance of the new column twice.