PostGIS  2.5.0beta2dev-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 1510 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().

1511 {
1512  LWCOLLECTION *col;
1513  LWPOLY *poly;
1514  uint32_t i;
1515 
1516  if ( (!in) || lwgeom_is_empty(in) ) return;
1517 
1518  /* TODO: check for lwgeom NOT having the specified dimension ? */
1519 
1520  LWDEBUGF(4, "lwgeom_flip_coordinates, got type: %s",
1521  lwtype_name(in->type));
1522 
1523  switch (in->type)
1524  {
1525  case POINTTYPE:
1526  ptarray_swap_ordinates(lwgeom_as_lwpoint(in)->point, o1, o2);
1527  break;
1528 
1529  case LINETYPE:
1530  ptarray_swap_ordinates(lwgeom_as_lwline(in)->points, o1, o2);
1531  break;
1532 
1533  case CIRCSTRINGTYPE:
1534  ptarray_swap_ordinates(lwgeom_as_lwcircstring(in)->points, o1, o2);
1535  break;
1536 
1537  case POLYGONTYPE:
1538  poly = (LWPOLY *) in;
1539  for (i=0; i<poly->nrings; i++)
1540  {
1541  ptarray_swap_ordinates(poly->rings[i], o1, o2);
1542  }
1543  break;
1544 
1545  case TRIANGLETYPE:
1546  ptarray_swap_ordinates(lwgeom_as_lwtriangle(in)->points, o1, o2);
1547  break;
1548 
1549  case MULTIPOINTTYPE:
1550  case MULTILINETYPE:
1551  case MULTIPOLYGONTYPE:
1552  case COLLECTIONTYPE:
1553  case COMPOUNDTYPE:
1554  case CURVEPOLYTYPE:
1555  case MULTISURFACETYPE:
1556  case MULTICURVETYPE:
1557  case POLYHEDRALSURFACETYPE:
1558  case TINTYPE:
1559  col = (LWCOLLECTION *) in;
1560  for (i=0; i<col->ngeoms; i++)
1561  {
1562  lwgeom_swap_ordinates(col->geoms[i], o1, o2);
1563  }
1564  break;
1565 
1566  default:
1567  lwerror("lwgeom_swap_ordinates: unsupported geometry type: %s",
1568  lwtype_name(in->type));
1569  return;
1570  }
1571 
1572  /* only refresh bbox if X or Y changed */
1573  if ( in->bbox && (o1 < 2 || o2 < 2) )
1574  {
1575  lwgeom_refresh_bbox(in);
1576  }
1577 }
#define LINETYPE
Definition: liblwgeom.h:85
GBOX * bbox
Definition: liblwgeom.h:400
#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:698
void lwgeom_swap_ordinates(LWGEOM *in, LWORD o1, LWORD o2)
Swap ordinate values in every vertex of the geometry.
Definition: lwgeom.c:1510
#define TRIANGLETYPE
Definition: liblwgeom.h:97
#define POLYHEDRALSURFACETYPE
Definition: liblwgeom.h:96
LWTRIANGLE * lwgeom_as_lwtriangle(const LWGEOM *lwgeom)
Definition: lwgeom.c:215
uint32_t ngeoms
Definition: liblwgeom.h:509
uint32_t nrings
Definition: liblwgeom.h:457
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:170
LWGEOM ** geoms
Definition: liblwgeom.h:511
#define TINTYPE
Definition: liblwgeom.h:98
POINTARRAY ** rings
Definition: liblwgeom.h:459
LWCIRCSTRING * lwgeom_as_lwcircstring(const LWGEOM *lwgeom)
Definition: lwgeom.c:179
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:1393
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:89
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:161
#define MULTISURFACETYPE
Definition: liblwgeom.h:95
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:84
uint8_t type
Definition: liblwgeom.h:398
#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: