PostGIS  2.5.0dev-r@@SVN_REVISION@@
void lwgeom_swap_ordinates ( LWGEOM in,
LWORD  o1,
LWORD  o2 
)

Swap ordinate values in every vertex of the geometry.

Ordinates to swap are specified using an index with meaning: 0=x, 1=y, 2=z, 3=m

Swapping an existing ordinate with an unexisting one results in undefined value being written in the existing ordinate. Caller should verify and prevent such calls.

Availability: 2.2.0

Definition at line 1503 of file lwgeom.c.

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

Referenced by do_lwgeom_swap_ordinates(), ST_FlipCoordinates(), and ST_SwapOrdinates().

1504 {
1505  LWCOLLECTION *col;
1506  LWPOLY *poly;
1507  uint32_t i;
1508 
1509  if ( (!in) || lwgeom_is_empty(in) ) return;
1510 
1511  /* TODO: check for lwgeom NOT having the specified dimension ? */
1512 
1513  LWDEBUGF(4, "lwgeom_flip_coordinates, got type: %s",
1514  lwtype_name(in->type));
1515 
1516  switch (in->type)
1517  {
1518  case POINTTYPE:
1519  ptarray_swap_ordinates(lwgeom_as_lwpoint(in)->point, o1, o2);
1520  break;
1521 
1522  case LINETYPE:
1523  ptarray_swap_ordinates(lwgeom_as_lwline(in)->points, o1, o2);
1524  break;
1525 
1526  case CIRCSTRINGTYPE:
1527  ptarray_swap_ordinates(lwgeom_as_lwcircstring(in)->points, o1, o2);
1528  break;
1529 
1530  case POLYGONTYPE:
1531  poly = (LWPOLY *) in;
1532  for (i=0; i<poly->nrings; i++)
1533  {
1534  ptarray_swap_ordinates(poly->rings[i], o1, o2);
1535  }
1536  break;
1537 
1538  case TRIANGLETYPE:
1539  ptarray_swap_ordinates(lwgeom_as_lwtriangle(in)->points, o1, o2);
1540  break;
1541 
1542  case MULTIPOINTTYPE:
1543  case MULTILINETYPE:
1544  case MULTIPOLYGONTYPE:
1545  case COLLECTIONTYPE:
1546  case COMPOUNDTYPE:
1547  case CURVEPOLYTYPE:
1548  case MULTISURFACETYPE:
1549  case MULTICURVETYPE:
1550  case POLYHEDRALSURFACETYPE:
1551  case TINTYPE:
1552  col = (LWCOLLECTION *) in;
1553  for (i=0; i<col->ngeoms; i++)
1554  {
1555  lwgeom_swap_ordinates(col->geoms[i], o1, o2);
1556  }
1557  break;
1558 
1559  default:
1560  lwerror("lwgeom_swap_ordinates: unsupported geometry type: %s",
1561  lwtype_name(in->type));
1562  return;
1563  }
1564 
1565  /* only refresh bbox if X or Y changed */
1566  if ( in->bbox && (o1 < 2 || o2 < 2) )
1567  {
1568  lwgeom_refresh_bbox(in);
1569  }
1570 }
#define LINETYPE
Definition: liblwgeom.h:85
GBOX * bbox
Definition: liblwgeom.h:397
#define MULTICURVETYPE
Definition: liblwgeom.h:94
#define POLYGONTYPE
Definition: liblwgeom.h:86
#define CURVEPOLYTYPE
Definition: liblwgeom.h:93
#define COMPOUNDTYPE
Definition: liblwgeom.h:92
#define MULTIPOINTTYPE
Definition: liblwgeom.h:87
void lwgeom_refresh_bbox(LWGEOM *lwgeom)
Drop current bbox and calculate a fresh one.
Definition: lwgeom.c:691
void lwgeom_swap_ordinates(LWGEOM *in, LWORD o1, LWORD o2)
Swap ordinate values in every vertex of the geometry.
Definition: lwgeom.c:1503
#define TRIANGLETYPE
Definition: liblwgeom.h:97
#define POLYHEDRALSURFACETYPE
Definition: liblwgeom.h:96
LWTRIANGLE * lwgeom_as_lwtriangle(const LWGEOM *lwgeom)
Definition: lwgeom.c:214
uint32_t ngeoms
Definition: liblwgeom.h:506
uint32_t nrings
Definition: liblwgeom.h:454
unsigned int uint32_t
Definition: uthash.h:78
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:218
void ptarray_swap_ordinates(POINTARRAY *pa, LWORD o1, LWORD o2)
Swap ordinate values o1 and o2 on a given POINTARRAY.
Definition: ptarray.c:387
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:169
LWGEOM ** geoms
Definition: liblwgeom.h:508
#define TINTYPE
Definition: liblwgeom.h:98
POINTARRAY ** rings
Definition: liblwgeom.h:456
LWCIRCSTRING * lwgeom_as_lwcircstring(const LWGEOM *lwgeom)
Definition: lwgeom.c:178
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:1386
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:89
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:160
#define MULTISURFACETYPE
Definition: liblwgeom.h:95
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:84
uint8_t type
Definition: liblwgeom.h:395
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:91
#define MULTILINETYPE
Definition: liblwgeom.h:88
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
#define COLLECTIONTYPE
Definition: liblwgeom.h:90

Here is the call graph for this function:

Here is the caller graph for this function: