PostGIS  2.5.7dev-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.

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 COLLECTIONTYPE
Definition: liblwgeom.h:91
#define COMPOUNDTYPE
Definition: liblwgeom.h:93
#define CURVEPOLYTYPE
Definition: liblwgeom.h:94
#define MULTILINETYPE
Definition: liblwgeom.h:89
#define MULTISURFACETYPE
Definition: liblwgeom.h:96
#define LINETYPE
Definition: liblwgeom.h:86
#define MULTIPOINTTYPE
Definition: liblwgeom.h:88
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:85
#define TINTYPE
Definition: liblwgeom.h:99
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:90
#define POLYGONTYPE
Definition: liblwgeom.h:87
#define POLYHEDRALSURFACETYPE
Definition: liblwgeom.h:97
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:92
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:218
#define MULTICURVETYPE
Definition: liblwgeom.h:95
#define TRIANGLETYPE
Definition: liblwgeom.h:98
void ptarray_swap_ordinates(POINTARRAY *pa, LWORD o1, LWORD o2)
Swap ordinate values o1 and o2 on a given POINTARRAY.
Definition: ptarray.c:387
void lwgeom_refresh_bbox(LWGEOM *lwgeom)
Drop current bbox and calculate a fresh one.
Definition: lwgeom.c:698
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:170
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:161
LWTRIANGLE * lwgeom_as_lwtriangle(const LWGEOM *lwgeom)
Definition: lwgeom.c:215
void lwgeom_swap_ordinates(LWGEOM *in, LWORD o1, LWORD o2)
Swap ordinate values in every vertex of the geometry.
Definition: lwgeom.c:1510
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
LWCIRCSTRING * lwgeom_as_lwcircstring(const LWGEOM *lwgeom)
Definition: lwgeom.c:179
#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
uint32_t ngeoms
Definition: liblwgeom.h:510
LWGEOM ** geoms
Definition: liblwgeom.h:512
uint8_t type
Definition: liblwgeom.h:399
GBOX * bbox
Definition: liblwgeom.h:401
POINTARRAY ** rings
Definition: liblwgeom.h:460
uint32_t nrings
Definition: liblwgeom.h:458
unsigned int uint32_t
Definition: uthash.h:78

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(), lwgeom_swap_ordinates(), 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(), lwgeom_swap_ordinates(), ST_FlipCoordinates(), and ST_SwapOrdinates().

Here is the call graph for this function:
Here is the caller graph for this function: