PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ lwgeom_swap_ordinates()

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 1513 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().

1514 {
1515  LWCOLLECTION *col;
1516  LWPOLY *poly;
1517  int i;
1518 
1519  if ( (!in) || lwgeom_is_empty(in) ) return;
1520 
1521  /* TODO: check for lwgeom NOT having the specified dimension ? */
1522 
1523  LWDEBUGF(4, "lwgeom_flip_coordinates, got type: %s",
1524  lwtype_name(in->type));
1525 
1526  switch (in->type)
1527  {
1528  case POINTTYPE:
1529  ptarray_swap_ordinates(lwgeom_as_lwpoint(in)->point, o1, o2);
1530  break;
1531 
1532  case LINETYPE:
1533  ptarray_swap_ordinates(lwgeom_as_lwline(in)->points, o1, o2);
1534  break;
1535 
1536  case CIRCSTRINGTYPE:
1537  ptarray_swap_ordinates(lwgeom_as_lwcircstring(in)->points, o1, o2);
1538  break;
1539 
1540  case POLYGONTYPE:
1541  poly = (LWPOLY *) in;
1542  for (i=0; i<poly->nrings; i++)
1543  {
1544  ptarray_swap_ordinates(poly->rings[i], o1, o2);
1545  }
1546  break;
1547 
1548  case TRIANGLETYPE:
1549  ptarray_swap_ordinates(lwgeom_as_lwtriangle(in)->points, o1, o2);
1550  break;
1551 
1552  case MULTIPOINTTYPE:
1553  case MULTILINETYPE:
1554  case MULTIPOLYGONTYPE:
1555  case COLLECTIONTYPE:
1556  case COMPOUNDTYPE:
1557  case CURVEPOLYTYPE:
1558  case MULTISURFACETYPE:
1559  case MULTICURVETYPE:
1560  case POLYHEDRALSURFACETYPE:
1561  case TINTYPE:
1562  col = (LWCOLLECTION *) in;
1563  for (i=0; i<col->ngeoms; i++)
1564  {
1565  lwgeom_swap_ordinates(col->geoms[i], o1, o2);
1566  }
1567  break;
1568 
1569  default:
1570  lwerror("lwgeom_swap_ordinates: unsupported geometry type: %s",
1571  lwtype_name(in->type));
1572  return;
1573  }
1574 
1575  /* only refresh bbox if X or Y changed */
1576  if ( in->bbox && (o1 < 2 || o2 < 2) )
1577  {
1578  lwgeom_drop_bbox(in);
1579  lwgeom_add_bbox(in);
1580  }
1581 }
#define LINETYPE
Definition: liblwgeom.h:86
GBOX * bbox
Definition: liblwgeom.h:398
#define MULTICURVETYPE
Definition: liblwgeom.h:95
void lwgeom_drop_bbox(LWGEOM *lwgeom)
Call this function to drop BBOX and SRID from LWGEOM.
Definition: lwgeom.c:635
#define POLYGONTYPE
Definition: liblwgeom.h:87
#define CURVEPOLYTYPE
Definition: liblwgeom.h:94
#define COMPOUNDTYPE
Definition: liblwgeom.h:93
#define MULTIPOINTTYPE
Definition: liblwgeom.h:88
void lwgeom_swap_ordinates(LWGEOM *in, LWORD o1, LWORD o2)
Swap ordinate values in every vertex of the geometry.
Definition: lwgeom.c:1513
#define TRIANGLETYPE
Definition: liblwgeom.h:98
#define POLYHEDRALSURFACETYPE
Definition: liblwgeom.h:97
LWTRIANGLE * lwgeom_as_lwtriangle(const LWGEOM *lwgeom)
Definition: lwgeom.c:183
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:388
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:138
LWGEOM ** geoms
Definition: liblwgeom.h:509
#define TINTYPE
Definition: liblwgeom.h:99
POINTARRAY ** rings
Definition: liblwgeom.h:457
int nrings
Definition: liblwgeom.h:455
LWCIRCSTRING * lwgeom_as_lwcircstring(const LWGEOM *lwgeom)
Definition: lwgeom.c:147
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:1346
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:90
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:129
#define MULTISURFACETYPE
Definition: liblwgeom.h:96
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:85
void lwgeom_add_bbox(LWGEOM *lwgeom)
Ensure there&#39;s a box in the LWGEOM.
Definition: lwgeom.c:648
uint8_t type
Definition: liblwgeom.h:396
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:92
#define MULTILINETYPE
Definition: liblwgeom.h:89
#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:91
Here is the call graph for this function:
Here is the caller graph for this function: