0

I'm using python 3.6 and postgres DB

I have a table name: test_table with the following fields: name (text), geo (geometry)

the srid of geo field is 32636

I want to write a python function which get point X (wkt) and return point Y with distance of 10 meters between the points. i.e:

The X and Y are in WKT format

How can I calculate the point Y with X is the input ?

It seems that I can't use euclidean distance , because the srid is 32636

so how can I do it ?

Jim Jones
  • 18,404
  • 3
  • 35
  • 44
Boom
  • 1,145
  • 18
  • 44
  • could you add an example of how these points + resultset would look like? – Jim Jones Sep 22 '20 at 14:56
  • The X and Y are in WKT format – Boom Sep 22 '20 at 14:58
  • great. can you add them to the question? – Jim Jones Sep 22 '20 at 14:59
  • how to add them ? the function gets X as wkt and need to calculate Y (wkt) which the distance between X and Y is 10 meters (srid=32636) – Boom Sep 22 '20 at 15:02
  • Just add the WKT of your geometry to the question. It is normally recommended to use `geography` instead of `geometry` for calculating distances in meters. – Jim Jones Sep 22 '20 at 15:08
  • 2
    Isn't 32636 UTM zone 36? Then Euclidean distances should work just fine, unless you need crazy accuracy, in which case you probably need to consider local topography as well... – Ture Pålsson Sep 22 '20 at 17:48

1 Answers1

4

You could cast your geometry to geography and ST_Project it (in the azimuth you want). Doing so you can easily provide the distance in meters:

CREATE TEMPORARY TABLE test_table (name text, geo geometry(point,(32636)));
INSERT INTO test_table VALUES ('foo','SRID=32636;POINT(2076155.32235105 4828109.18280588)');

SELECT 
 ST_AsText(
  ST_Transform(
   ST_Project(
     ST_Transform(geo,4326)::geography,10,radians(45.0))::geometry,
   32636)
 )
FROM test_table;

                st_astext                 
------------------------------------------
 POINT(2076150.11319696 4828116.26815917)
(1 Zeile)

You can check the distance using ST_Distance:

SELECT 
  ST_Distance(
    ST_Transform(geo,4326)::geography,
    ST_Project(ST_Transform(geo,4326)::geography,10,radians(45.0))::geometry )
FROM test_table;

st_distance 
-------------
          10

NOTE: I'm using ST_Transform to get from your projected SRS to a lon/lat SRS, so that we can cast it to geography, otherwise we'd get an error:

SELECT geo::geography FROM test_table;

ERROR:  Only lon/lat coordinate systems are supported in geography.

Further reading: Caculate point 50 miles away (North, 45% NE, 45% SW)

Jim Jones
  • 18,404
  • 3
  • 35
  • 44