[postgis-users] Get point certain degree of another point

Mike Toews mwtoews at sfu.ca
Sat Jan 23 13:26:50 PST 2010


On 2010-01-22 19:05, tommy408 wrote:
> How can I get a point at a certain distance and degree from another point.
> For example 10 meter distance to another point at 45 degrees.
>    

You could also use some simple trigonometry with ST_Translate().

For example, consider 'geom' at (100 100), and a point 12 units away 30 
degrees from the x-axis (math style with CCW direction .. or a 
geographic bearing of 60 degrees CW from North).

SELECT AsEWKT(ST_Translate(geom, cos(rad)*dist, sin(rad)*dist))
FROM (select ST_MakePoint(100, 100) as geom, 12 as dist, 30*2*pi()/360 
as rad) AS foo;

POINT(110.392304845413 106)

Or your example from (0 0) using a math-style angle:

SELECT AsEWKT(ST_Translate(geom, cos(rad)*dist, sin(rad)*dist))
FROM (select ST_MakePoint(0, 0) as geom, 10 as dist, 45*2*pi()/360 as 
rad) AS foo;

POINT(7.07106781186548 7.07106781186547)

This could easily be turned into a PL/pgSQL function if you require it 
frequently. Also, be aware of the geographic versus mathematics 
definition of angles, since they have opposite rotations and start 90 
degrees from each other.

-Mike



More information about the postgis-users mailing list