[postgis-users] Reverse X and Y coordinates?

Kevin Neufeld kneufeld at refractions.net
Fri Dec 18 19:02:53 PST 2009


What about rotating about the line y=x?

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)

-- Kevin

Anthony McClure wrote:
> Good day,
>
> I have a problem that I cannot find a solution to.  I have the X and Y 
> coordinates reversed in the geometries within my database.  I need the 
> X's to become Y's and the Y's to become X's.  The geometries are all 
> polygons or multi-polygons.  Is there anything within PostGIS I can 
> execute SQL wise to do this?
>
> The only other thing I can think of is to write code to go through all 
> of the points and reverse them manually which obviously I am hoping to 
> avoid.
>
> Thanks for the help,
> Anthony
> This email, and any attachments thereto, is intended
> only for use by the addressee(s) named herein and may
> contain legally privileged and/or confidential information.  
> If you are not the intended recipient of this email, you 
> are hereby notified that any dissemination, distribution 
> or copying of this email, and any attachments thereto, 
> is strictly prohibited.  If you have received this e-mail in 
> error, please immediately and permanently delete the 
> original and any copy of any email and any printout 
> thereof. 
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users



More information about the postgis-users mailing list