Changes between Version 11 and Version 12 of UsersWikiplpgsqlfunctions
- Timestamp:
- 09/09/09 21:32:39 (15 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
UsersWikiplpgsqlfunctions
v11 v12 5 5 == This is an area to put utility functions or wrappers around PostGIS == 6 6 7 * '''Generate an arc given two points on the arc and the centre point'''7 * '''Generate an arc given two points on the arc, the centre point and direction''' 8 8 9 9 {{{ 10 10 #!sql 11 CREATE OR REPLACE FUNCTION st_createarc(startpoint geometry, endpoint geometry, arcenter geometry )11 CREATE OR REPLACE FUNCTION st_createarc(startpoint geometry, endpoint geometry, arcenter geometry,direction text) 12 12 RETURNS geometry AS 13 13 $$ … … 15 15 pointonarc geometry; 16 16 thearc text; 17 thedirection float; 17 18 BEGIN 18 pointonarc := ST_Translate( ST_Rotate( ST_Translate( startpoint, -1*ST_X(arcenter), -1*ST_Y(arcenter)), pi()/5), ST_X(arcenter), ST_Y(arcenter)); 19 thearc := 'CIRCULARSTRING('||ST_X(startpoint)||' '||ST_Y(startpoint)||','||ST_X(pointonarc)||' '||ST_Y(pointonarc)||','||ST_X(endpoint)||' '||ST_Y(endpoint)||')'; 19 IF direction = 'cc' THEN thedirection := pi()/5; ELSE thedirection := -1*pi()/5; END IF; 20 pointonarc := ST_Translate( ST_Rotate( ST_Translate( startpoint, -1*ST_X(arcenter), -1*ST_Y(arcenter)), thedirection), ST_X(arcenter), ST_Y(arcenter)); 21 thearc := 'CIRCULARSTRING('||ST_X(startpoint)||' '||ST_Y(startpoint)||','||ST_X(pointonarc)||' '||ST_Y(pointonarc)||','||ST_X(endpoint)||' '||ST_Y(endpoint)||')'; 20 22 RETURN st_transform(st_curvetoline(st_transform(st_setsrid(thearc,st_srid(arcenter)),utmzone(arcenter))),st_srid(arcenter)); 21 23 END; 22 24 $$ 23 25 LANGUAGE 'plpgsql' IMMUTABLE; 24 COMMENT ON FUNCTION st_createarc(geometry,geometry,geometry) IS 'Generates an arc based on starting point, ending point and centre of arc. All geometries must be of type POINT and this function returns a linestring of the arc based on the original SRID and 32 points per quarter circle. Requires the utmzone function.'; 26 COMMENT ON FUNCTION st_createarc(geometry,geometry,geometry,text) IS 'Generates an arc based on starting point, ending point,centre of arc, and direction. All geometries must be of type POINT and direction must be "cc" (counter-clockwise) or "cw" (clockwise).This function returns a linestring of the arc based on the original SRID and 32 points per quarter circle. Requires the utmzone function.'; 27 25 28 }}} 26 29