PostGIS  2.3.7dev-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 1477 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_swap_ordinates(), LWPOLY::rings, TINTYPE, TRIANGLETYPE, and LWGEOM::type.

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

1478 {
1479  LWCOLLECTION *col;
1480  LWPOLY *poly;
1481  int i;
1482 
1483 #if PARANOIA_LEVEL > 0
1484  assert(o1 < 4);
1485  assert(o2 < 4);
1486 #endif
1487 
1488  if ( (!in) || lwgeom_is_empty(in) ) return;
1489 
1490  /* TODO: check for lwgeom NOT having the specified dimension ? */
1491 
1492  LWDEBUGF(4, "lwgeom_flip_coordinates, got type: %s",
1493  lwtype_name(in->type));
1494 
1495  switch (in->type)
1496  {
1497  case POINTTYPE:
1498  ptarray_swap_ordinates(lwgeom_as_lwpoint(in)->point, o1, o2);
1499  break;
1500 
1501  case LINETYPE:
1502  ptarray_swap_ordinates(lwgeom_as_lwline(in)->points, o1, o2);
1503  break;
1504 
1505  case CIRCSTRINGTYPE:
1506  ptarray_swap_ordinates(lwgeom_as_lwcircstring(in)->points, o1, o2);
1507  break;
1508 
1509  case POLYGONTYPE:
1510  poly = (LWPOLY *) in;
1511  for (i=0; i<poly->nrings; i++)
1512  {
1513  ptarray_swap_ordinates(poly->rings[i], o1, o2);
1514  }
1515  break;
1516 
1517  case TRIANGLETYPE:
1518  ptarray_swap_ordinates(lwgeom_as_lwtriangle(in)->points, o1, o2);
1519  break;
1520 
1521  case MULTIPOINTTYPE:
1522  case MULTILINETYPE:
1523  case MULTIPOLYGONTYPE:
1524  case COLLECTIONTYPE:
1525  case COMPOUNDTYPE:
1526  case CURVEPOLYTYPE:
1527  case MULTISURFACETYPE:
1528  case MULTICURVETYPE:
1529  case POLYHEDRALSURFACETYPE:
1530  case TINTYPE:
1531  col = (LWCOLLECTION *) in;
1532  for (i=0; i<col->ngeoms; i++)
1533  {
1534  lwgeom_swap_ordinates(col->geoms[i], o1, o2);
1535  }
1536  break;
1537 
1538  default:
1539  lwerror("lwgeom_swap_ordinates: unsupported geometry type: %s",
1540  lwtype_name(in->type));
1541  return;
1542  }
1543 
1544  /* only refresh bbox if X or Y changed */
1545  if ( in->bbox && (o1 < 2 || o2 < 2) )
1546  {
1547  lwgeom_drop_bbox(in);
1548  lwgeom_add_bbox(in);
1549  }
1550 }
#define LINETYPE
Definition: liblwgeom.h:85
GBOX * bbox
Definition: liblwgeom.h:397
#define MULTICURVETYPE
Definition: liblwgeom.h:94
void lwgeom_drop_bbox(LWGEOM *lwgeom)
Call this function to drop BBOX and SRID from LWGEOM.
Definition: lwgeom.c:599
#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_swap_ordinates(LWGEOM *in, LWORD o1, LWORD o2)
Swap ordinate values in every vertex of the geometry.
Definition: lwgeom.c:1477
#define TRIANGLETYPE
Definition: liblwgeom.h:97
#define POLYHEDRALSURFACETYPE
Definition: liblwgeom.h:96
LWTRIANGLE * lwgeom_as_lwtriangle(const LWGEOM *lwgeom)
Definition: lwgeom.c:147
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:216
void ptarray_swap_ordinates(POINTARRAY *pa, LWORD o1, LWORD o2)
Swap ordinate values o1 and o2 on a given POINTARRAY.
Definition: ptarray.c:388
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:102
LWGEOM ** geoms
Definition: liblwgeom.h:508
#define TINTYPE
Definition: liblwgeom.h:98
POINTARRAY ** rings
Definition: liblwgeom.h:456
int nrings
Definition: liblwgeom.h:454
LWCIRCSTRING * lwgeom_as_lwcircstring(const LWGEOM *lwgeom)
Definition: lwgeom.c:111
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:1310
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:89
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:93
#define MULTISURFACETYPE
Definition: liblwgeom.h:95
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:84
void lwgeom_add_bbox(LWGEOM *lwgeom)
Ensure there's a box in the LWGEOM.
Definition: lwgeom.c:612
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:102
#define COLLECTIONTYPE
Definition: liblwgeom.h:90

Here is the call graph for this function:

Here is the caller graph for this function: