Changes between Initial Version and Version 1 of UsersWikiCardinalDirection

Show
Ignore:
Timestamp:
10/26/11 19:17:04 (2 years ago)
Author:
mwtoews
Comment:

contribute

Legend:

Unmodified
Added
Removed
Modified
  • UsersWikiCardinalDirection

    v1 v1  
     1= Determine Cardinal Direction = 
     2 
     3See [http://en.wikipedia.org/wiki/Cardinal_direction Wikipedia] for a description for cardinal direction. 
     4 
     5{{{ 
     6-- Function: ST_Cardinal_Direction(azimuth float8) 
     7-- Returns N, NW, W, SW, S, SE, E, or NE from an azimuth direction 
     8-- By: Mike Toews 
     9-- 
     10-- Usage: 
     11-- postgis=# SELECT ST_Cardinal_Direction( 
     12-- postgis(#          ST_Azimuth('POINT(3 5)', 'POINT(5 5)')); 
     13--  st_cardinal_direction 
     14-- ----------------------- 
     15--  E 
     16-- (1 row) 
     17-- 
     18-- DROP FUNCTION ST_Cardinal_Direction(float8); 
     19 
     20CREATE OR REPLACE FUNCTION ST_Cardinal_Direction(azimuth float8) 
     21  RETURNS character varying AS 
     22$BODY$SELECT CASE 
     23WHEN $1 < 0.0 THEN 'less than 0' 
     24WHEN $1*180/pi() < 22.5 THEN 'N' 
     25WHEN $1*180/pi() < 67.5 THEN 'NE' 
     26WHEN $1*180/pi() < 112.5 THEN 'E' 
     27WHEN $1*180/pi() < 157.5 THEN 'SE' 
     28WHEN $1*180/pi() < 202.5 THEN 'S' 
     29WHEN $1*180/pi() < 247.5 THEN 'SW' 
     30WHEN $1*180/pi() < 292.5 THEN 'W' 
     31WHEN $1*180/pi() < 337.5 THEN 'NW' 
     32WHEN $1*180/pi() <= 360.0 THEN 'N' 
     33END;$BODY$ LANGUAGE sql IMMUTABLE COST 100; 
     34COMMENT ON FUNCTION ST_Cardinal_Direction(float8) IS 'input azimuth in radians; returns N, NW, W, SW, S, SE, E, or NE'; 
     35}}}