PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ lwgeom_count_rings()

uint32_t lwgeom_count_rings ( const LWGEOM geom)

Count the total number of rings in any LWGEOM.

Multipolygons and other collections get counted, not the same as OGC st_numrings.

Count the total number of rings in any LWGEOM.

Definition at line 1339 of file lwgeom.c.

1340 {
1341  int result = 0;
1342 
1343  /* Null? Empty? Zero. */
1344  if( ! geom || lwgeom_is_empty(geom) )
1345  return 0;
1346 
1347  switch (geom->type)
1348  {
1349  case POINTTYPE:
1350  case CIRCSTRINGTYPE:
1351  case COMPOUNDTYPE:
1352  case MULTICURVETYPE:
1353  case MULTIPOINTTYPE:
1354  case MULTILINETYPE:
1355  case LINETYPE:
1356  result = 0;
1357  break;
1358  case TRIANGLETYPE:
1359  result = 1;
1360  break;
1361  case POLYGONTYPE:
1362  result = ((LWPOLY *)geom)->nrings;
1363  break;
1364  case CURVEPOLYTYPE:
1365  result = ((LWCURVEPOLY *)geom)->nrings;
1366  break;
1367  case MULTISURFACETYPE:
1368  case MULTIPOLYGONTYPE:
1369  case POLYHEDRALSURFACETYPE:
1370  case TINTYPE:
1371  case COLLECTIONTYPE:
1372  {
1373  LWCOLLECTION *col = (LWCOLLECTION*)geom;
1374  uint32_t i = 0;
1375  for( i = 0; i < col->ngeoms; i++ )
1376  result += lwgeom_count_rings(col->geoms[i]);
1377  break;
1378  }
1379  default:
1380  lwerror("lwgeom_count_rings: unsupported input geometry type: %s", lwtype_name(geom->type));
1381  break;
1382  }
1383  LWDEBUGF(3, "counted %d rings", result);
1384  return result;
1385 }
#define COLLECTIONTYPE
Definition: liblwgeom.h:122
#define COMPOUNDTYPE
Definition: liblwgeom.h:124
#define CURVEPOLYTYPE
Definition: liblwgeom.h:125
#define MULTILINETYPE
Definition: liblwgeom.h:120
#define MULTISURFACETYPE
Definition: liblwgeom.h:127
#define LINETYPE
Definition: liblwgeom.h:117
#define MULTIPOINTTYPE
Definition: liblwgeom.h:119
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:116
#define TINTYPE
Definition: liblwgeom.h:130
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:121
#define POLYGONTYPE
Definition: liblwgeom.h:118
#define POLYHEDRALSURFACETYPE
Definition: liblwgeom.h:128
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:123
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:216
#define MULTICURVETYPE
Definition: liblwgeom.h:126
#define TRIANGLETYPE
Definition: liblwgeom.h:129
uint32_t lwgeom_count_rings(const LWGEOM *geom)
Count rings in an LWGEOM.
Definition: lwgeom.c:1339
#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
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition: lwinline.h:193
uint32_t ngeoms
Definition: liblwgeom.h:566
LWGEOM ** geoms
Definition: liblwgeom.h:561
uint8_t type
Definition: liblwgeom.h:448

References CIRCSTRINGTYPE, COLLECTIONTYPE, COMPOUNDTYPE, CURVEPOLYTYPE, LWCOLLECTION::geoms, LINETYPE, LWDEBUGF, lwerror(), lwgeom_count_rings(), lwgeom_is_empty(), lwtype_name(), MULTICURVETYPE, MULTILINETYPE, MULTIPOINTTYPE, MULTIPOLYGONTYPE, MULTISURFACETYPE, LWCOLLECTION::ngeoms, POINTTYPE, POLYGONTYPE, POLYHEDRALSURFACETYPE, TINTYPE, TRIANGLETYPE, and LWGEOM::type.

Referenced by lwgeom_count_rings(), and LWGEOM_nrings().

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