| 1 | = Functions for the geography type = |
| 2 | |
| 3 | == Great Circle Mapper == |
| 4 | [http://www.gcmap.com 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. |
| 5 | |
| 6 | This helper function returns a URL for the Great Circle Mapper website that shows the path of a geography linestring on the Earth. |
| 7 | |
| 8 | {{{ |
| 9 | CREATE FUNCTION ST_AsGreatCircleMapperURL(geography) RETURNS text AS |
| 10 | $BODY$SELECT 'http://www.gcmap.com/mapui?P=' || |
| 11 | string_agg( |
| 12 | abs(ST_Y(geom))::text || |
| 13 | CASE WHEN ST_Y(geom) < 0 THEN 'S' ELSE 'N' END |
| 14 | || '+' || |
| 15 | abs(ST_X(geom))::text || |
| 16 | CASE WHEN ST_X(geom) < 0 THEN 'W' ELSE 'E' END, |
| 17 | '-') || '&MS=wls&DU=km' AS url |
| 18 | FROM ST_DumpPoints($1::geometry)$BODY$ |
| 19 | LANGUAGE sql IMMUTABLE; |
| 20 | }}} |
| 21 | |
| 22 | Examples: |
| 23 | {{{ |
| 24 | SELECT ST_AsGreatCircleMapperURL('POLYGON ((35 10, 45 45, -15 40, -10 20, 35 10))'::geography); |
| 25 | }}} |
| 26 | http://www.gcmap.com/mapui?P=10N+35E-45N+45E-40N+15W-20N+10W-10N+35E&MS=wls&DU=km |
| 27 | |
| 28 | {{{ |
| 29 | SELECT ST_AsGreatCircleMapperURL(ST_MakeEnvelope(-75, -80, 110, 3)::geography); |
| 30 | }}} |
| 31 | http://www.gcmap.com/mapui?P=80S+75W-3N+75W-3N+110E-80S+110E-80S+75W&MS=wls&DU=km |