1

I have a PostGIS (PostgreSQL 13/PostGIS 3.1.1 on Debian 11.7) table with points in EPSG:6708, so it's plain coordinates (data from Northern Italy). I need to get lat/long coordinates, so I do:

    SELECT ST_AsText(the_geom) AS xy, ST_AsText(ST_Transform(the_geom,4326)) AS ll FROM acq_impianti WHERE gid=426;
                         xy                     |                    ll                     
    --------------------------------------------+-------------------------------------------
     POINT(291349.5482259364 5072882.274108588) | POINT(52.9750863624063 2.074122662821441)

which is absolutely wrong; in fact if I do the same transformation using this tool, I obtain: enter image description here

I can't figure out what I'm doing wrong....

EDIT: Using ST_FlipCoordinates solves the problem, but maybe there is a better way to handle this

SELECT ST_AsText(the_geom) AS xy, ST_AsText(ST_Transform(ST_FlipCoordinates(the_geom),4326)) AS ll FROM acq_impianti WHERE gid=426;                     xy                     |                     ll                      
--------------------------------------------+---------------------------------------------
 POINT(291349.5482259364 5072882.274108588) | POINT(12.316072170259908 45.77796903086367)
7
  • are you sure the data in the table is stored in the correct projection?
    – Ian Turton
    Commented Oct 10, 2023 at 13:01
  • 1
    Probably some confusion with x/y order but I can't say where. EPSG:6708 is a northing-easting system.
    – user30184
    Commented Oct 10, 2023 at 13:04
  • 1
    Its definitely an X/Y vs Y/X problem, I tried it both ways round in R and in one order get the value in the question and the other gets the value in the screenshot...
    – Spacedman
    Commented Oct 10, 2023 at 13:46
  • OK, is there a way to "swap" X with Y? Commented Oct 10, 2023 at 14:36
  • 1
    Do you know how the data are inserted into the database? Maybe the coordinates have been swapped once then, and now you need to swap them again.
    – user30184
    Commented Oct 10, 2023 at 15:10

1 Answer 1

1

You can swap the X & Y coordinates like this:

UPDATE your_table
SET your_geom_column = ST_SetSRID(ST_MakePoint(ST_Y(your_geom_column ), ST_X(your_geom_column )), ST_SRID(your_geom_column))
WHERE your_condition = whatever;

Hope it helps my friend. In geom

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.