Changes between Version 5 and Version 6 of UsersWikiplpgsqlfunctions
- Timestamp:
- 04/19/09 00:39:50 (16 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
UsersWikiplpgsqlfunctions
v5 v6 7 7 * '''Find UTM (WGS84) SRID for a point (in any SRID)''' 8 8 9 {{{ 9 {{{ 10 #!sql 10 11 -- Function: utmzone(geometry) 11 12 -- DROP FUNCTION utmzone(geometry); … … 20 21 21 22 BEGIN 22 geomgeog:= transform($1,4326);23 geomgeog:= ST_Transform($1,4326); 23 24 24 IF ( y(geomgeog))>0 THEN25 IF (ST_Y(geomgeog))>0 THEN 25 26 pref:=32600; 26 27 ELSE … … 28 29 END IF; 29 30 30 zone:=floor(( x(geomgeog)+180)/6)+1;31 zone:=floor((ST_X(geomgeog)+180)/6)+1; 31 32 32 33 RETURN zone+pref; … … 38 39 * '''Find Length of Day for a given location and date''' 39 40 {{{ 41 #!sql 40 42 CREATE OR REPLACE FUNCTION daylength(geometry, date) 41 RETURNS double precision AS 'select 24*(ACOS(1-(1-TAN(radians(Y(transform($1,4326))))*TAN(.409088 * COS(.0172024 * extract(doy from $2)))))/PI());' 43 RETURNS double precision AS 44 $$ 45 SELECT 24*(ACOS(1-(1-TAN(radians(Y(transform($1,4326))))*TAN(.409088 * COS(.0172024 * extract(doy from $2)))))/PI()); 46 $$ 42 47 LANGUAGE 'sql'; 43 48 }}} … … 45 50 * '''Rotate Geometry around a point(geom,x,y)''' 46 51 {{{ 52 #!sql 47 53 CREATE OR REPLACE FUNCTION RotateAtPoint(geometry, double precision, double precision, double precision) 48 RETURNS geometry AS 'SELECT translate( rotate( translate( $1, -1*$2, -1*$3), $4), $2, $3)' 54 RETURNS geometry AS 55 $$ 56 SELECT ST_Translate( ST_Rotate( ST_Translate( $1, -1*$2, -1*$3), $4), $2, $3) 57 $$ 49 58 LANGUAGE 'sql'; 50 59 }}} … … 52 61 * '''Create Ellipse (x,y,rx,ry,rotation,#of segments in 1/4 of ellipse)''' 53 62 {{{ 63 #!sql 54 64 CREATE OR REPLACE FUNCTION Ellipse(double precision, double precision, double precision, double precision, double precision, integer) 55 65 RETURNS geometry AS 56 'SELECT translate( rotate( scale( buffer(makepoint(0,0), 0.5, $6), $3, $4), $5), $1, $2)' 66 $$ 67 SELECT ST_Translate( ST_Rotate( ST_Scale( ST_Buffer(ST_Point(0,0), 0.5, $6), $3, $4), $5), $1, $2) 68 $$ 57 69 LANGUAGE 'sql'; 58 70 }}}