Let's say I run the following query on a PostgreSQL database with the PostGIS extension:
SELECT ST_AsText((ST_Transform('SRID=4326;POINT(-34.91148366443491 -8.077603972529051)',3857)));
The result is:
POINT(-3886328.584362583 -902188.317568294)
However, when I try to do it the other way around:
SELECT ST_AsText(ST_Transform('SRID=3857;POINT(-3886328.584362583 -902188.317568294)', 4326 ));
The result is:
POINT(-34.91148366443491 -8.077603972529053)
Even though it was the same conversion the last result is different from the original one. That brings me some problems if I try to compare the last result with the first. How should I be handling this? I thought about diminishing the precision of the final and original results in order to get comparisons right, but I don't think that's the right way of handling it. How can I deal with precision problems generated by the ST_Transform function?
WHEREstatement I'll get no results. It's not clear to me how I'd handle it. if I consider that 5 decimal places are enough for me (1 meter precision), what would be the most straighforward way of handling it? Would remaking my original geometry column with 5 decimal places be the most appropriate way of handling it? Or should I just use a function that diminishes its precision when I want to make a comparison with=? – raylight Apr 22 '22 at 20:11SELECT ST_AsText( ST_Transform( (ST_Transform( ST_GeomFromText('POINT(-3886328.584362583 -902188.317568294)', 3857 ),4326)),3857));I recommend to use ST_SnapToGrid https://postgis.net/docs/ST_SnapToGrid.html for dealing with tolerances. – user30184 Apr 22 '22 at 20:22Precision reduction requires GEOS-3.9 or higher... I'm still trying to figure out a way of installing it onUbuntu 20.04. – raylight Apr 22 '22 at 20:29