PostGIS  2.2.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 1464 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().

1465 {
1466  LWCOLLECTION *col;
1467  LWPOLY *poly;
1468  int i;
1469 
1470 #if PARANOIA_LEVEL > 0
1471  assert(o1 < 4);
1472  assert(o2 < 4);
1473 #endif
1474 
1475  if ( (!in) || lwgeom_is_empty(in) ) return;
1476 
1477  /* TODO: check for lwgeom NOT having the specified dimension ? */
1478 
1479  LWDEBUGF(4, "lwgeom_flip_coordinates, got type: %s",
1480  lwtype_name(in->type));
1481 
1482  switch (in->type)
1483  {
1484  case POINTTYPE:
1485  ptarray_swap_ordinates(lwgeom_as_lwpoint(in)->point, o1, o2);
1486  break;
1487 
1488  case LINETYPE:
1489  ptarray_swap_ordinates(lwgeom_as_lwline(in)->points, o1, o2);
1490  break;
1491 
1492  case CIRCSTRINGTYPE:
1493  ptarray_swap_ordinates(lwgeom_as_lwcircstring(in)->points, o1, o2);
1494  break;
1495 
1496  case POLYGONTYPE:
1497  poly = (LWPOLY *) in;
1498  for (i=0; i<poly->nrings; i++)
1499  {
1500  ptarray_swap_ordinates(poly->rings[i], o1, o2);
1501  }
1502  break;
1503 
1504  case TRIANGLETYPE:
1505  ptarray_swap_ordinates(lwgeom_as_lwtriangle(in)->points, o1, o2);
1506  break;
1507 
1508  case MULTIPOINTTYPE:
1509  case MULTILINETYPE:
1510  case MULTIPOLYGONTYPE:
1511  case COLLECTIONTYPE:
1512  case COMPOUNDTYPE:
1513  case CURVEPOLYTYPE:
1514  case MULTISURFACETYPE:
1515  case MULTICURVETYPE:
1516  case POLYHEDRALSURFACETYPE:
1517  case TINTYPE:
1518  col = (LWCOLLECTION *) in;
1519  for (i=0; i<col->ngeoms; i++)
1520  {
1521  lwgeom_swap_ordinates(col->geoms[i], o1, o2);
1522  }
1523  break;
1524 
1525  default:
1526  lwerror("lwgeom_swap_ordinates: unsupported geometry type: %s",
1527  lwtype_name(in->type));
1528  return;
1529  }
1530 
1531  /* only refresh bbox if X or Y changed */
1532  if ( in->bbox && (o1 < 2 || o2 < 2) )
1533  {
1534  lwgeom_drop_bbox(in);
1535  lwgeom_add_bbox(in);
1536  }
1537 }
#define LINETYPE
Definition: liblwgeom.h:71
GBOX * bbox
Definition: liblwgeom.h:382
#define MULTICURVETYPE
Definition: liblwgeom.h:80
void lwgeom_drop_bbox(LWGEOM *lwgeom)
Call this function to drop BBOX and SRID from LWGEOM.
Definition: lwgeom.c:586
#define POLYGONTYPE
Definition: liblwgeom.h:72
#define CURVEPOLYTYPE
Definition: liblwgeom.h:79
#define COMPOUNDTYPE
Definition: liblwgeom.h:78
#define MULTIPOINTTYPE
Definition: liblwgeom.h:73
void lwgeom_swap_ordinates(LWGEOM *in, LWORD o1, LWORD o2)
Swap ordinate values in every vertex of the geometry.
Definition: lwgeom.c:1464
#define TRIANGLETYPE
Definition: liblwgeom.h:83
#define POLYHEDRALSURFACETYPE
Definition: liblwgeom.h:82
LWTRIANGLE * lwgeom_as_lwtriangle(const LWGEOM *lwgeom)
Definition: lwgeom.c:134
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:188
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:89
LWGEOM ** geoms
Definition: liblwgeom.h:493
#define TINTYPE
Definition: liblwgeom.h:84
POINTARRAY ** rings
Definition: liblwgeom.h:441
int nrings
Definition: liblwgeom.h:439
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:1297
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:75
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:80
#define MULTISURFACETYPE
Definition: liblwgeom.h:81
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:70
void lwgeom_add_bbox(LWGEOM *lwgeom)
Ensure there's a box in the LWGEOM.
Definition: lwgeom.c:599
uint8_t type
Definition: liblwgeom.h:380
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:77
#define MULTILINETYPE
Definition: liblwgeom.h:74
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:55
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:74
#define COLLECTIONTYPE
Definition: liblwgeom.h:76

Here is the call graph for this function:

Here is the caller graph for this function: