PostGIS  2.5.7dev-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 1345 of file lwgeom.c.

1346 {
1347  int result = 0;
1348 
1349  /* Null? Empty? Zero. */
1350  if( ! geom || lwgeom_is_empty(geom) )
1351  return 0;
1352 
1353  switch (geom->type)
1354  {
1355  case POINTTYPE:
1356  case CIRCSTRINGTYPE:
1357  case COMPOUNDTYPE:
1358  case MULTICURVETYPE:
1359  case MULTIPOINTTYPE:
1360  case MULTILINETYPE:
1361  case LINETYPE:
1362  result = 0;
1363  break;
1364  case TRIANGLETYPE:
1365  result = 1;
1366  break;
1367  case POLYGONTYPE:
1368  result = ((LWPOLY *)geom)->nrings;
1369  break;
1370  case CURVEPOLYTYPE:
1371  result = ((LWCURVEPOLY *)geom)->nrings;
1372  break;
1373  case MULTISURFACETYPE:
1374  case MULTIPOLYGONTYPE:
1375  case POLYHEDRALSURFACETYPE:
1376  case TINTYPE:
1377  case COLLECTIONTYPE:
1378  {
1379  LWCOLLECTION *col = (LWCOLLECTION*)geom;
1380  uint32_t i = 0;
1381  for( i = 0; i < col->ngeoms; i++ )
1382  result += lwgeom_count_rings(col->geoms[i]);
1383  break;
1384  }
1385  default:
1386  lwerror("lwgeom_count_rings: unsupported input geometry type: %s", lwtype_name(geom->type));
1387  break;
1388  }
1389  LWDEBUGF(3, "counted %d rings", result);
1390  return result;
1391 }
#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
uint32_t lwgeom_count_rings(const LWGEOM *geom)
Count rings in an LWGEOM.
Definition: lwgeom.c:1345
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 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
unsigned int uint32_t
Definition: uthash.h:78

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: