PostGIS  2.1.10dev-r@@SVN_REVISION@@
LWGEOM* lwgeom_flip_coordinates ( LWGEOM in)

Reverse the X and Y coordinate order.

Useful for geometries in lat/lon order than need to be converted to lon/lat order.

Definition at line 1390 of file lwgeom.c.

References LWGEOM::bbox, CIRCSTRINGTYPE, COLLECTIONTYPE, COMPOUNDTYPE, CURVEPOLYTYPE, LWCOLLECTION::geoms, LINETYPE, LWDEBUGF, lwerror(), lwgeom_add_bbox(), lwgeom_as_lwcircstring(), lwgeom_as_lwline(), lwgeom_as_lwpoint(), lwgeom_as_lwtriangle(), lwgeom_drop_bbox(), lwgeom_is_empty(), lwtype_name(), MULTICURVETYPE, MULTILINETYPE, MULTIPOINTTYPE, MULTIPOLYGONTYPE, MULTISURFACETYPE, LWCOLLECTION::ngeoms, LWPOLY::nrings, POINTTYPE, POLYGONTYPE, POLYHEDRALSURFACETYPE, ptarray_flip_coordinates(), LWPOLY::rings, TINTYPE, TRIANGLETYPE, and LWGEOM::type.

Referenced by do_lwgeom_flip_coordinates(), and ST_FlipCoordinates().

1391 {
1392  LWCOLLECTION *col;
1393  LWPOLY *poly;
1394  int i;
1395 
1396  if ( (!in) || lwgeom_is_empty(in) )
1397  return in;
1398 
1399  LWDEBUGF(4, "lwgeom_flip_coordinates, got type: %s",
1400  lwtype_name(in->type));
1401 
1402  switch (in->type)
1403  {
1404  case POINTTYPE:
1406  break;
1407 
1408  case LINETYPE:
1410  break;
1411 
1412  case CIRCSTRINGTYPE:
1414  break;
1415 
1416  case POLYGONTYPE:
1417  poly = (LWPOLY *) in;
1418  for (i=0; i<poly->nrings; i++)
1419  {
1420  ptarray_flip_coordinates(poly->rings[i]);
1421  }
1422  break;
1423 
1424  case TRIANGLETYPE:
1426  break;
1427 
1428  case MULTIPOINTTYPE:
1429  case MULTILINETYPE:
1430  case MULTIPOLYGONTYPE:
1431  case COLLECTIONTYPE:
1432  case COMPOUNDTYPE:
1433  case CURVEPOLYTYPE:
1434  case MULTISURFACETYPE:
1435  case MULTICURVETYPE:
1436  case POLYHEDRALSURFACETYPE:
1437  case TINTYPE:
1438  col = (LWCOLLECTION *) in;
1439  for (i=0; i<col->ngeoms; i++)
1440  {
1441  lwgeom_flip_coordinates(col->geoms[i]);
1442  }
1443  break;
1444 
1445  default:
1446  lwerror("lwgeom_flip_coordinates: unsupported geometry type: %s",
1447  lwtype_name(in->type));
1448  return NULL;
1449  }
1450 
1451  /* only refresh bbox if X or Y changed */
1452  if ( in->bbox ) {
1453  lwgeom_drop_bbox(in);
1454  lwgeom_add_bbox(in);
1455  }
1456  return in;
1457 }
#define LINETYPE
Definition: liblwgeom.h:61
GBOX * bbox
Definition: liblwgeom.h:354
#define MULTICURVETYPE
Definition: liblwgeom.h:70
void lwgeom_drop_bbox(LWGEOM *lwgeom)
Call this function to drop BBOX and SRID from LWGEOM.
Definition: lwgeom.c:542
#define POLYGONTYPE
Definition: liblwgeom.h:62
#define CURVEPOLYTYPE
Definition: liblwgeom.h:69
#define COMPOUNDTYPE
Definition: liblwgeom.h:68
#define MULTIPOINTTYPE
Definition: liblwgeom.h:63
#define TRIANGLETYPE
Definition: liblwgeom.h:73
#define POLYHEDRALSURFACETYPE
Definition: liblwgeom.h:72
LWTRIANGLE * lwgeom_as_lwtriangle(const LWGEOM *lwgeom)
Definition: lwgeom.c:134
POINTARRAY * ptarray_flip_coordinates(POINTARRAY *pa)
Reverse X and Y axis on a given POINTARRAY.
Definition: ptarray.c:354
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:164
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:89
LWGEOM ** geoms
Definition: liblwgeom.h:465
#define TINTYPE
Definition: liblwgeom.h:74
POINTARRAY ** rings
Definition: liblwgeom.h:413
int nrings
Definition: liblwgeom.h:411
LWCIRCSTRING * lwgeom_as_lwcircstring(const LWGEOM *lwgeom)
Definition: lwgeom.c:98
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members) ...
Definition: lwgeom.c:1229
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:65
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:80
#define MULTISURFACETYPE
Definition: liblwgeom.h:71
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:60
void lwgeom_add_bbox(LWGEOM *lwgeom)
Ensure there's a box in the LWGEOM.
Definition: lwgeom.c:555
uint8_t type
Definition: liblwgeom.h:352
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:67
#define MULTILINETYPE
Definition: liblwgeom.h:64
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:55
LWGEOM * lwgeom_flip_coordinates(LWGEOM *in)
Reverse the X and Y coordinate order.
Definition: lwgeom.c:1390
#define COLLECTIONTYPE
Definition: liblwgeom.h:66

Here is the call graph for this function:

Here is the caller graph for this function: