Functions for the geography type

Great Circle Mapper

Great Circle Mapper is a website that shows lines on the globe that follow great circles, which is analogous to the shortest travel direction a plane would take between locations. The logic used for great circles is the same used for PostGIS' geography type.

This helper function returns a URL for the Great Circle Mapper website that shows the path of a geography linestring on the Earth.

CREATE FUNCTION ST_AsGreatCircleMapperURL(geography) RETURNS text AS
    abs(ST_Y(geom))::text ||
      CASE WHEN ST_Y(geom) < 0 THEN 'S' ELSE 'N' END
    || '+' ||
    abs(ST_X(geom))::text ||
      CASE WHEN ST_X(geom) < 0 THEN 'W' ELSE 'E' END,
  '-') || '&MS=wls&DU=km' AS url
FROM ST_DumpPoints($1::geometry)$BODY$


SELECT ST_AsGreatCircleMapperURL('POLYGON ((35 10, 45 45, -15 40, -10 20, 35 10))'::geography);

SELECT ST_AsGreatCircleMapperURL(ST_MakeEnvelope(-75, -80, 110, 3)::geography);

Last modified 4 years ago Last modified on Dec 2, 2013 3:12:09 PM