Changes between Version 12 and Version 13 of UsersWikiplpgsqlfunctions


Ignore:
Timestamp:
09/10/09 11:16:44 (15 years ago)
Author:
bcrosby
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • UsersWikiplpgsqlfunctions

    v12 v13  
    1616    thearc text;
    1717    thedirection float;
     18    midpointrads float;
     19    originalsrid int;
     20    arcenterutm geometry;
     21    startpointutm geometry;
     22    endpointutm geometry;
    1823  BEGIN
    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));
    2333  END;
    2434  $$
    2535  LANGUAGE 'plpgsql' IMMUTABLE;
    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
    2838}}}
    2939