| 3 | |
| 4 | * '''Find UTM (WGS84) SRID for a point (in any SRID)''' |
| 5 | {{{ |
| 6 | #!sql |
| 7 | -- Function: utmzone(geometry) |
| 8 | -- DROP FUNCTION utmzone(geometry); |
| 9 | |
| 10 | CREATE OR REPLACE FUNCTION utmzone(geometry) |
| 11 | RETURNS integer AS |
| 12 | $BODY$ |
| 13 | DECLARE |
| 14 | geomgeog geometry; |
| 15 | zone int; |
| 16 | pref int; |
| 17 | |
| 18 | BEGIN |
| 19 | geomgeog:= ST_Transform($1,4326); |
| 20 | |
| 21 | IF (ST_Y(geomgeog))>0 THEN |
| 22 | pref:=32600; |
| 23 | ELSE |
| 24 | pref:=32700; |
| 25 | END IF; |
| 26 | |
| 27 | zone:=floor((ST_X(geomgeog)+180)/6)+1; |
| 28 | |
| 29 | RETURN zone+pref; |
| 30 | END; |
| 31 | $BODY$ LANGUAGE 'plpgsql' IMMUTABLE |
| 32 | COST 100; |
| 33 | }}} |
| 34 | |