Changes between Version 11 and Version 12 of UsersWikiplpgsqlfunctions


Ignore:
Timestamp:
09/09/09 21:32:39 (15 years ago)
Author:
bcrosby
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • UsersWikiplpgsqlfunctions

    v11 v12  
    55==  This is an area to put utility functions or wrappers around PostGIS ==
    66
    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'''
    88
    99{{{
    1010#!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)
    1212  RETURNS geometry AS
    1313  $$
     
    1515    pointonarc geometry;
    1616    thearc text;
     17    thedirection float;
    1718  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)||')';
    2022        RETURN st_transform(st_curvetoline(st_transform(st_setsrid(thearc,st_srid(arcenter)),utmzone(arcenter))),st_srid(arcenter));
    2123  END;
    2224  $$
    2325  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 
    2528}}}
    2629