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)||')'; |
22 | | RETURN st_transform(st_curvetoline(st_transform(st_setsrid(thearc,st_srid(arcenter)),utmzone(arcenter))),st_srid(arcenter)); |
| 24 | arcenterutm := st_transform(arcenter,utmzone(arcenter)); |
| 25 | startpointutm := st_transform(startpoint,utmzone(startpoint)); |
| 26 | endpointutm := st_transform(endpoint,utmzone(endpoint)); |
| 27 | |
| 28 | midpointrads := abs(st_azimuth(startpointutm,arcenterutm) - st_azimuth(endpointutm,arcenterutm))/2; |
| 29 | IF direction = 'cw' THEN thedirection := -1*midpointrads; ELSE thedirection := midpointrads; END IF; |
| 30 | pointonarc := ST_Translate( ST_Rotate( ST_Translate( startpointutm, -1*ST_X(arcenterutm), -1*ST_Y(arcenterutm)), thedirection), ST_X(arcenterutm), ST_Y(arcenterutm)); |
| 31 | thearc := 'CIRCULARSTRING('||ST_X(startpointutm)||' '||ST_Y(startpointutm)||','||ST_X(pointonarc)||' '||ST_Y(pointonarc)||','||ST_X(endpointutm)||' '||ST_Y(endpointutm)||')'; |
| 32 | RETURN st_transform(st_setsrid(st_curvetoline(thearc),utmzone(arcenter)),st_srid(arcenter)); |
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 | | |
| 36 | COMMENT ON FUNCTION st_createarc(geometry,geometry,geometry,text) IS 'Generates an arc based on starting point, ending point, centre of arc, and direction (clockwise: 'cw', counter-clockwise: 'cc'). 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.'; |
| 37 | |