[postgis-users] Proposed new functions

Bruce Rindahl rindahl at lrcwe.com
Sun Mar 11 12:44:43 PDT 2007


I would like to propose the following functions be added to PostGIS.  They
are shortcuts to some affine transformations that people have recently been
asking about.  The code is as follows:

-- Function: RotateAtPoint(geometry, double precision, double precision,
double precision)

-- DROP FUNCTION RotateAtPoint(geometry, double precision, double precision,
double precision);

CREATE OR REPLACE FUNCTION RotateAtPoint(geometry, double precision, double
precision, double precision)
RETURNS geometry AS
'SELECT translate( rotate( translate( $1, -1*$2, -1*$3), $4), $2, $3)'
  LANGUAGE 'sql' IMMUTABLE STRICT;
ALTER FUNCTION RotateAtPoint(geometry, double precision, double precision,
double precision) OWNER TO postgres;


-- Function: Ellipse(double precision, double precision, double precision,
double precision, double precision, integer)

-- DROP FUNCTION Ellipse(double precision, double precision, double
precision, double precision, double precision, integer);

CREATE OR REPLACE FUNCTION Ellipse(double precision, double precision,
double precision, double precision, double precision, integer)
  RETURNS geometry AS
'SELECT translate( rotate( scale( buffer(makepoint(0,0), 1, $6), $3, $4),
$5), $1, $2)'
  LANGUAGE 'sql' IMMUTABLE STRICT;
ALTER FUNCTION Ellipse(double precision, double precision, double precision,
double precision, double precision, integer) OWNER TO postgres;


-- Function: Ellipse(double precision, double precision, double precision,
double precision, double precision)

-- DROP FUNCTION Ellipse(double precision, double precision, double
precision, double precision, double precision);

CREATE OR REPLACE FUNCTION Ellipse(double precision, double precision,
double precision, double precision, double precision)
  RETURNS geometry AS
'SELECT translate( rotate( scale( buffer(makepoint(0,0), 1), $3, $4), $5),
$1, $2)'
  LANGUAGE 'sql' IMMUTABLE STRICT;
ALTER FUNCTION Ellipse(double precision, double precision, double precision,
double precision, double precision) OWNER TO postgres;



The first function rotates a geometry about a point specified by x, y.
The second function creates an ellipse by specifying the center (x,y) the
major and minor axis length, the rotation angle, and the number of segments
in a quarter of the ellipse.  The third function is identical to the first
except the number of segments is not supplied and set to the default of 8.

Note the functions use three separate calls to the affine function so they
could be recast as one call if someone wants to multiply the matrices
together to speed up the functions.  I kind of like them this way as they
clearly show how the functions are performed.

Documentation:

<varlistentry>
  <term>RotateAtPoint(geometry, x, y, rotation)</term> 
  <listitem>
    <para>Rotates the geometry around the point specified by x and y by the
given angle in radians.  X, Y, and rotation parameters must be float8
values</para> 
    <para>Availability: ???</para> 
  </listitem>
</varlistentry>

<varlistentry>
  <term>Ellipse(x, y, a, b, rotation, segments)</term> 
  <listitem>
    <para>Creates an polygon approximating an ellipse centered at x, y with
major axis a, minor axis length b, rotated by the given angle in radians.
The optional segments parameter specifies the number of line segments in a
quarter of the ellipse.  If not specified it will default to 8.  Increasing
this number will add segments to more closely approximate an ellipse.  If
specified the segments parameter must be an integer, all other parameters
are float8. </para> 
    <para>Availability: ???</para> 
  </listitem>
</varlistentry>



Thanks!
Bruce Rindahl





More information about the postgis-users mailing list