Re: [postgis-users] new functions

2012-01-09 Thread Mike Toews
Also another comment for your transrotate function: you can use 1 call
to ST_Affine, rather than 3 indirect calls with
st_rotate(st_translate(st_rotate(. You just need to wrangle the
trigonometry in the affine transformation matrix correctly.

I have an enhancement for a st_rotate with a point of origin in trac,
where you can see how to use ST_Affine for this purpose:
http://trac.osgeo.org/postgis/ticket/1251

-Mike
___
postgis-users mailing list
postgis-users@postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users


Re: [postgis-users] new functions

2012-01-09 Thread Peter Korduan

Am 09.01.2012 21:12, schrieb Mike Toews:

Also another comment for your transrotate function: you can use 1 call
to ST_Affine, rather than 3 indirect calls with
st_rotate(st_translate(st_rotate(. You just need to wrangle the
trigonometry in the affine transformation matrix correctly.

I have an enhancement for a st_rotate with a point of origin in trac,
where you can see how to use ST_Affine for this purpose:
http://trac.osgeo.org/postgis/ticket/1251

-Mike
Yes Mike, my transrotate function is a special case of an affine 
transformation. I have to consider the quadrants for the trigonometry 
calculation when i use st_affine. I will check it out. Thanks.
Even if the form one after another shows exactly what happens, other 
than in the affine transformation.


To the second comment with the point of origin:
Nice to have it, but i think in my case its not necessary if rotating in 
one direction and than in the opposite with the same origin.


But nevertheless, many thanks for the comments, nice conversation.

Peter
___
postgis-users mailing list
postgis-users@postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users


Re: [postgis-users] new functions

2012-01-05 Thread Ralf Suhr
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 precisionDEFAULT  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(450 600)',2398) AS start_point,
 GeomFromText('POINT(451 601)',2398) AS end_point,
 1::float AS abszisse,
 0::float AS ordinate
 ) AS value_table
 Must return:
 POINT(450.70710678 599.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)
 ';
___
postgis-users mailing list
postgis-users@postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users


[postgis-users] new functions

2012-01-04 Thread Peter Korduan

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(450 600)',2398) AS start_point,
GeomFromText('POINT(451 601)',2398) AS end_point,
1::float AS abszisse,
0::float AS ordinate
) AS value_table
Must return:
POINT(450.70710678 599.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

___
postgis-users mailing list
postgis-users@postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users


Re: [postgis-users] new functions

2012-01-04 Thread Sandro Santilli
On Wed, Jan 04, 2012 at 07:07:16PM +0100, Peter Korduan wrote:

 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.

Peter, I suggest you write them to the postgis wiki
which contain other contributed functions.

If you think they could be ready for integration you should file
them in a ticket togheter with regression testing and documentation.

--strk;

  ,--o-. 
  |   __/  |Thank you for PostGIS-2.0 Topology !
  |  / 2.0 |http://www.pledgebank.com/postgistopology
  `-o--'

___
postgis-users mailing list
postgis-users@postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users