0

My goal here is to take a polygonal area defined in latitude-longitude coordinates (SRID=4326) and translate it to another place on the globe while preserving size and shape. I had thought to use ST_Translate for this as follows:

SELECT ST_AsText(ST_Translate(ST_GeomFromEWKT('SRID=4326;POLYGON((38.436047 -9.103183,38.431081 -9.1005,38.427922 -9.109997,38.432886 -9.112686,38.436047 -9.103183))'),-8.344589,-76.890003)) As wgs_transgeomtxt;
                                               wgs_transgeomtxt                                               
--------------------------------------------------------------------------------------------------------------
 POLYGON((30.091458 -85.993186,30.086492 -85.990503,30.083333 -86,30.088297 -86.002689,30.091458 -85.993186))
(1 row)

However, when I compare the side lengths of the resulting polygon versus the original, they are not the same. Using just the first two points:

SELECT ST_Length(the_geog) As length_spheroid,  ST_Length(the_geog,false) As length_sphere FROM (SELECT ST_GeographyFromText('SRID=4326;LINESTRING(38.436047 -9.103183,38.431081 -9.1005)') As the_geog) As foo;
  length_spheroid  |   length_sphere   
-------------------+-------------------
 621.3389574115513 | 621.5250338349151

for the original versus

SELECT ST_Length(the_geog) As length_spheroid,  ST_Length(the_geog,false) As length_sphere FROM (SELECT ST_GeographyFromText('SRID=4326;LINESTRING(30.091458 -85.993186,30.086492 -85.990503)') As the_geog) As foo;
  length_spheroid   |   length_sphere    
--------------------+--------------------
 302.15778025327586 | 300.82283651431646
(1 row)

for the transformed. Is this some artifact of how ST_Translate works and is there a way to correct for it? Or am I using the wrong function entirely?

teddybouch
  • 81
  • 5
  • How are you measuring the lengths? – Ian Turton Aug 23 '21 at 15:23
  • I mapped the coordinates in Google Maps and I'm using its distance tool. – teddybouch Aug 23 '21 at 15:26
  • But since you asked and that's a really good point, I double-checked with the calculator at link – teddybouch Aug 23 '21 at 15:38
  • 1
    So you converted to ESPG:3857 - Please do not ever use EPSG:3857 (Web Mercator) to carry out any sort of distance related analysis. The longitude (X) axis is distorted to infinity as you move north or south of the Equator. In this case I would use PostGIS' geography type's st_length() – Ian Turton Aug 23 '21 at 15:47
  • Thanks - I didn't know that both those services converted to a different format in the background. However, that doesn't solve my problem; using ST_Length as you suggested actually shows a much bigger difference in lengths between the original and the transformed. I'll edit the question so I can show what I'm getting. – teddybouch Aug 23 '21 at 16:27
  • 2
    Distance between two meridians are not the same everywhere but gets shorter towards the poles. Your theory that ST_Transform with EPSG:4326 (or with geography) preserves lengths and areas is wrong. Unfortunately I can't say what coordinate system would be good for your use case. – user30184 Aug 23 '21 at 17:28
  • Probably you would need to use a Discrete Global Grid System (DGGS) https://geoawesomeness.com/discrete-global-grid-system-dggs-new-reference-system/. I do not know if there are any implementations available yet. – user30184 Aug 23 '21 at 18:02

0 Answers0