[postgis-users] new functions
Ralf Suhr
Ralf.Suhr at itc-halle.de
Thu Jan 5 01:41:08 PST 2012
Hi Peter,
you can enhance your functions with features from postgresql >=8.4:
+ overloading in one function
+ named parameter
SELECT transrotate( ordinate := 1, start_point := 'POINT( 11 52)' );
CREATE OR REPLACE FUNCTION transrotate
(
IN start_point geometry,
IN azimuth double precision DEFAULT 0,
IN abscissa float DEFAULT 0,
IN ordinate float DEFAULT 0,
OUT point geometry
)
AS
$$
BEGIN
SELECT
ST_Rotate(
ST_Translate(
ST_Rotate(
start_point,
azimuth
),
abscissa,
ordinate
),
-azimuth
)
INTO point;
END;
$$
LANGUAGE plpgsql;
Gr
Ralf
On Mittwoch 04 Januar 2012 19:07:16 Peter Korduan wrote:
> Hi,
>
> hny, my name is Peter. I'm new to the list, but working with PostGIS a
> while.
> Allow me to post you 2 functions, i wrote recently. These might be
> useful to you or at least worth to integrate in postgis.sql at all.
> The first calculate a point starting from a start point perpendicular to
> a direction with a distance.
> In the second i use this function to interpolate a point not direct on a
> line, but next beside in the distance d. Its similar to
> line_interpolate_point, but left or right from the line.
> It might be useful e.g. if you want to calculate the position of a tree
> on a road by a given station number an the perpendicular distance or
> other objects next beside a liniar feature of the real world or for
> construction calculation.
> In the comments you will find tests to find out how it works.
>
> Any hints and comments are welcome,
>
> Best Regards
> Peter Korduan
>
> CREATE OR REPLACE FUNCTION transrotate(geometry, double precision,
> float, float)
> RETURNS geometry AS
> $BODY$SELECT
> st_rotate(
> st_translate(
> st_rotate(
> start_point,
> azimuth
> ),
> abscissa,
> ordinate
> ),
> -azimuth
> ) AS geometry
> FROM (
> SELECT
> $1 AS start_point,
> $2 AS azimuth,
> $3 AS abscissa,
> $4 AS ordinate
>
> ) AS value_table$BODY$
> LANGUAGE sql IMMUTABLE STRICT
> cost 100;
> COMMENT ON FUNCTION st_transrotate(geometry, double precision, double
> precision, double precision) IS 'args: startPointGeometry, azimuth in
> radiant, abscissa in m, ordinate in m - Translates the abscissa and
> ordinate on a survey line starting in startPoint with azimuth direction
> into a point geometry in the coordinate reference system of the
> startpoint, working in 2D only.
> test:
> SELECT asText(transrotate(start_point, st_azimuth(start_point,
> end_point),abszisse, ordinate)) FROM (
> SELECT
> GeomFromText('POINT(4500000 6000000)',2398) AS start_point,
> GeomFromText('POINT(4500001 6000001)',2398) AS end_point,
> 1::float AS abszisse,
> 0::float AS ordinate
> ) AS value_table
> Must return:
> "POINT(4500000.70710678 5999999.29289322)"
> ';
>
> CREATE OR REPLACE FUNCTION dline_interpolate_point(geometry, float, float)
> RETURNS geometry AS
> $BODY$SELECT
> transrotate(
> st_line_interpolate_point(linestring, fraction),
> st_azimuth(
> st_line_interpolate_point(linestring, fraction-0.0002),
> st_line_interpolate_point(linestring, fraction+0.0002)
> ),
> abscissa,
> ordinate
> ) AS geometry
> FROM (
> SELECT
> $1 AS linestring,
> $2 AS fraction,
> $3 AS abscissa,
> 0::float AS ordinate
>
> ) AS value_table$BODY$
> LANGUAGE sql IMMUTABLE STRICT
> cost 100;
> COMMENT ON FUNCTION dline_interpolate_point(geometry, float, float) IS
> 'args: a_linestring, a_fraction, a_abscissa - Returns a point
> interpolated along a line. Second argument is a float8 between 0 and 1
> representing fraction of total length of linestring the point has to be
> located. Third argument is a float8 and calculates the point on the
> abscissa left or right from the line depending on the sign of the
> argument positive = right or negative = left and the direction of the
> line. If the third argument is 0, the point will be calculated on the
> line similar to st_line_interpolate_point. The function transrotate is
> required.
> test:
> SELECT ST_AsEWKT(dline_interpolate_point(the_line, 0.50, 1))
> FROM (SELECT ST_GeomFromEWKT('LINESTRING(0 0, 100 100)') as the_line) As
> foo;
> returns:
> "POINT(50.7071067811866 49.2928932188135)"
> SELECT ST_AsEWKT(dline_interpolate_point(the_line, 0.50, 0))
> FROM (SELECT ST_GeomFromEWKT('LINESTRING(0 0, 100 100)') as the_line) As
> foo;
> returns:
> "POINT(50 50)"
> ';
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20120105/589468db/attachment.html>
More information about the postgis-users
mailing list