Changes between Version 19 and Version 20 of UsersWikiplpgsqlfunctions


Ignore:
Timestamp:
Oct 12, 2009, 6:06:12 PM (15 years ago)
Author:
robe
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • UsersWikiplpgsqlfunctions

    v19 v20  
    44
    55==  This is an area to put utility functions or wrappers around PostGIS ==
    6 [wiki:UsersWikiplpgsqlfunctionsDistance Distance PL/PGSQL/SQL Functions]
     6[wiki:UsersWikiplpgsqlfunctionsDistance Distance /Spatial Reference support functions PL/PGSQL/SQL Functions]
    77
    88 * '''Generate an arc given two points on the arc, the centre point and direction'''
     
    4848
    4949
    50 }}}
    51 
    52  * '''Find UTM (WGS84)  SRID for a point (in any SRID)'''
    53 
    54 {{{
    55 #!sql
    56  -- Function: utmzone(geometry)
    57  -- DROP FUNCTION utmzone(geometry);
    58 
    59  CREATE OR REPLACE FUNCTION utmzone(geometry)
    60    RETURNS integer AS
    61  $BODY$
    62  DECLARE
    63      geomgeog geometry;
    64      zone int;
    65      pref int;
    66 
    67  BEGIN
    68      geomgeog:= ST_Transform($1,4326);
    69 
    70      IF (ST_Y(geomgeog))>0 THEN
    71         pref:=32600;
    72      ELSE
    73         pref:=32700;
    74      END IF;
    75 
    76      zone:=floor((ST_X(geomgeog)+180)/6)+1;
    77 
    78      RETURN zone+pref;
    79  END;
    80  $BODY$ LANGUAGE 'plpgsql' IMMUTABLE
    81    COST 100;
    8250}}}
    8351