Opened 15 years ago

Closed 15 years ago

#354 closed enhancement (fixed)

ST_FlipCoordinates(geometry)

Reported by: pramsey Owned by: pramsey
Priority: low Milestone: PostGIS 2.0.0
Component: postgis Version: master
Keywords: Cc:

Description

Given POINT(Y,X) return POINT(X,Y). Ditto for all other types. Useful for people who have built latitude/longitude features and need to fix them.

Change History (2)

comment:1 by kneufeld, 15 years ago

Until this gets implemented in C, this could be a simple SQL function wrapper.

It's been many years since I've done matrix algebra so I might not have this exactly right, but this does seem to work.

SELECT ST_AsText(ST_Affine(
 column1,
 cos(pi()/2), sin(pi()/2),
 sin(pi()/2), cos(pi()/2),
  0,          0
))
FROM (VALUES
 ('POINT(4 3)'),
 ('LINESTRING(1 2, 59 34, -9 3)'),
 ('POLYGON (( 2 13, 6 12, 4 8, 2 7, 2 13 ),
            ( 4 12, 3 10, 3 9, 4 10, 4 12 ))')
) a; 
                          st_astext                          
-------------------------------------------------------------
 POINT(3 4)
 LINESTRING(2 1,34 59,3 -9)
 POLYGON((13 2,12 6,8 4,7 2,13 2),(12 4,10 3,9 3,10 4,12 4))
(3 rows)

Note: anyone wishing to use ST_Affine to swap ordinates may need to push the results through ST_SnapToGrid since matrix computation is done on the coordinates.

SELECT ST_AsText(ST_Affine(
 'POINT(0 4)'::geometry,
 cos(pi()/2), sin(pi()/2),
 sin(pi()/2), cos(pi()/2),
  0,          0
           st_astext            
--------------------------------
 POINT(4 2.44929359829471e-016)
(1 row)
)); 

comment:2 by colivier, 15 years ago

Resolution: fixed
Status: newclosed

Done as r5338 (Kind of easy homework achieved in the plane)

Note: See TracTickets for help on using tickets.