2

If I have a starting point as well as distance and a bearing to the destination point, how can I find the coordinates of the destination point using PostGIS?

I'm looking for a PostGIS equivalent to this function: http://www.movable-type.co.uk/scripts/latlong.html#destPoint

2

Use the ST_Project() function:

geography ST_Project (geography geog, float distance, float azimuth);

It returns a point "projected" from a start point using a distance in meters and bearing (azimuth) in radians.

You may need to first cast your geometry to a geography

goem::geography

convert your azimuth from degrees to radians

radians (azimuth)

and your distance to meters, if necessary. And remember to cast your resulting geography back to a geometry.


In my opinion, "project" is not the best name for this function, even though it makes sense literally (pro-ject = "throw forward"):

  • geomatics already has two or three existing phrases for this activity/calculation: traverse and forward/direct problem
  • project already means something else in geomatics: to transfer from the spheroid to the map/plane

    • Thanks, this is what I was looking for. Didn't think to look in the geography functions. – Alex Korban May 14 '14 at 9:57
    3

    This is basically the same thing I said here, just modified to produce the end point instead of a line:

    SELECT
        objectid,
        ST_SetSRID(ST_Translate(ST_Rotate(ST_MakePoint(-1 * dist_field,0.0),
                                          radians(bearing_field)), ST_X(the_geom),  
                                ST_Y(the_geom)),ST_SRID(the_geom)) AS end_point_geom
    FROM start_points
    

    Where start_points is the table containing your starting points, the_geom in that table is the geometry column, dist_field is the distance field and bearing_field is the bearing field.

    You may need to change the direction of the initial line (ST_MakePoint(-1 * dist_field,0.0)) to vertical (swap the coordinates/field name) depending on how you are measuring your bearing.

    • Thanks, I'll use this if ST_Project causes performance issues. – Alex Korban May 14 '14 at 9:58

    Your Answer

    By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

    Not the answer you're looking for? Browse other questions tagged or ask your own question.