| 6 | |
| 7 | * '''Generate an arc given two points on the arc and the centre point''' |
| 8 | |
| 9 | {{{ |
| 10 | #!sql |
| 11 | CREATE OR REPLACE FUNCTION st_createarc(startpoint geometry, endpoint geometry, arcenter geometry) |
| 12 | RETURNS geometry AS |
| 13 | $$ |
| 14 | DECLARE |
| 15 | pointonarc geometry; |
| 16 | thearc text; |
| 17 | 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)||')'; |
| 20 | RETURN st_transform(st_curvetoline(st_transform(st_setsrid(thearc,st_srid(arcenter)),utmzone(arcenter))),st_srid(arcenter)); |
| 21 | END; |
| 22 | $$ |
| 23 | 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.'; |
| 25 | }}} |