3

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

Martin F
  • 8,948
  • 36
  • 58
Alex Korban
  • 133
  • 1
  • 5

2 Answers2

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.

Evil Genius
  • 6,289
  • 2
  • 27
  • 40
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
  • Martin F
    • 8,948
    • 36
    • 58