-1

I am looking to find multiple lat/long points (N,S,E,W) that are 100 metres from an input lat/lon point I have stored in PostGIS.

Given a latitude and longitude I'd like to find the latitude and longitude point that is 100 metres North, 100 metres South etc.

I don't have anything but the input lat/lon values stored in the database, so SELECTing from PostGIS will not work in this case.

According to @ThingumaBob, there is a way to find these points with PostGIS.

How would I do this?

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Matt
  • 11
  • 4

1 Answers1

2

To create 4 Points, one in each direction (NESW) at 100m distance to each input point, you can use ST_Project:

SELECT ip.<id_column> AS id,
       dir.arr[n+1] as direction,
       ST_AsText(ST_Project(ip.<geometry_column>::geography, 100.0, radians(90.0*n))) AS geom
FROM <input_points_table> AS ip CROSS JOIN generate_series(0, 3) AS n,
     (SELECT ARRAY['N', 'E', 'S', 'W'] AS arr) AS dir

I used generate_series to auto-increment the bearing and select the direction letter from the array.

This should return 4 points with their direction, for each point in <input_points_table>, with the respective ids from their <id_column>. It assumes your input points are georeferenced in EPSG:4326 (WGS84)!

Note: this returns the new point's geometries in WKT format (via ST_AsText(...)) so you can read their LatLng values. This doesn't save/store anything; if you want to use those geometries programmatically, you need to explain how you want them stored.

geozelot
  • 30,050
  • 4
  • 32
  • 56