[postgis-users] new functions
Peter Korduan
peter.korduan at uni-rostock.de
Wed Jan 4 10:07:16 PST 2012
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)"
';
--
Universität Rostock
Professur für Geodäsie und Geoinformatik
Justus-von-Liebig-Weg 6
D-18059 Rostock
Tel: 0381/4983212
Fax: 0381/4983202
More information about the postgis-users
mailing list