docs/en/sql-reference/functions/geo/flipCoordinates.md
The flipCoordinates function swaps the coordinates of a point, ring, polygon, or multipolygon. This is useful, for example, when converting between coordinate systems where the order of latitude and longitude differs.
flipCoordinates(coordinates)
coordinates — A tuple representing a point (x, y), or an array of such tuples representing a ring, polygon, or multipolygon. Supported input types include:
(x, y) where x and y are Float64 values.[(x1, y1), (x2, y2), ...].[ring1, ring2, ...], where each ring is an array of points.[polygon1, polygon2, ...].The function returns the input with the coordinates flipped. For example:
(x, y) becomes (y, x).[(x1, y1), (x2, y2)] becomes [(y1, x1), (y2, x2)].SELECT flipCoordinates((10, 20)) AS flipped_point
┌─flipped_point─┐
│ (20,10) │
└───────────────┘
SELECT flipCoordinates([(10, 20), (30, 40)]) AS flipped_ring
┌─flipped_ring──────────────┐
│ [(20,10),(40,30)] │
└───────────────────────────┘
SELECT flipCoordinates([[(10, 20), (30, 40)], [(50, 60), (70, 80)]]) AS flipped_polygon
┌─flipped_polygon──────────────────────────────┐
│ [[(20,10),(40,30)],[(60,50),(80,70)]] │
└──────────────────────────────────────────────┘
SELECT flipCoordinates([[[10, 20], [30, 40]], [[50, 60], [70, 80]]]) AS flipped_multipolygon
┌─flipped_multipolygon──────────────────────────────┐
│ [[[20,10],[40,30]],[[60,50],[80,70]]] │
└───────────────────────────────────────────────────┘