3

In PostGIS, Is there a way to calculate another point 50 miles away in different directions?

Given a point, ('New York',-74.00,40.71), how do I calculate the following points?

1) 50 miles directly North
2) 50 miles 45% North East
4) 50 miles directly East
3) 50 miles 45% South West

Update: It seems http://postgis.net/docs/ST_Project.html may be the solution.

ST_Project('POINT(-74.00 40.71)'::geography, 80467.2, radians(45.0))

However, I need to reference the database record to do it. not hard code it.

Jim Jones
  • 18,404
  • 3
  • 35
  • 44
user2012677
  • 5,465
  • 6
  • 51
  • 113

1 Answers1

2

Try combining ST_Project with a CTE - adjust the values of radians to the azimuth you need.

WITH j AS (
  SELECT poi::geography AS poi FROM t
)
SELECT 
  ST_AsText(ST_Project(j.poi, 80467.2, radians(90.0)),2),
  ST_AsText(ST_Project(j.poi, 80467.2, radians(45.0)),2),
  ST_AsText(ST_Project(j.poi, 80467.2, radians(180.0)),2),
  ST_AsText(ST_Project(j.poi, 80467.2, radians(135.0)),2),
  ST_AsText(ST_Project(j.poi, 80467.2, radians(270.0)),2),
  ST_AsText(ST_Project(j.poi, 80467.2, radians(225.0)),2),
  ST_AsText(ST_Project(j.poi, 80467.2, radians(360.0)),2),
  ST_AsText(ST_Project(j.poi, 80467.2, radians(315.0)),2)
FROM j;

      st_astext      |      st_astext      |    st_astext     |     st_astext      |      st_astext      |     st_astext      |    st_astext     |      st_astext      
---------------------+---------------------+------------------+--------------------+---------------------+--------------------+------------------+---------------------
 POINT(-73.05 40.71) | POINT(-73.32 41.22) | POINT(-74 39.99) | POINT(-73.33 40.2) | POINT(-74.95 40.71) | POINT(-74.67 40.2) | POINT(-74 41.43) | POINT(-74.68 41.22)
(1 Zeile)

enter image description here

Note: The buffer (circle) in the image is just for illustration.

Jim Jones
  • 18,404
  • 3
  • 35
  • 44
  • 1
    I was trying to replicate this I think.. https://stackoverflow.com/questions/59848162/st-hexagongrid-geom-vector-to-find-all-points. But this seems like a better solution if I can resolve it. More upvotes as your answers have been amazing! – user2012677 Jan 21 '20 at 19:45