PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ lwgeom_count_rings()

uint32_t lwgeom_count_rings ( const LWGEOM geom)

Count rings in an LWGEOM.

Count the total number of rings in any LWGEOM.

Definition at line 1344 of file lwgeom.c.

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

Referenced by LWGEOM_nrings().

1345 {
1346  int result = 0;
1347 
1348  /* Null? Empty? Zero. */
1349  if( ! geom || lwgeom_is_empty(geom) )
1350  return 0;
1351 
1352  switch (geom->type)
1353  {
1354  case POINTTYPE:
1355  case CIRCSTRINGTYPE:
1356  case COMPOUNDTYPE:
1357  case MULTICURVETYPE:
1358  case MULTIPOINTTYPE:
1359  case MULTILINETYPE:
1360  case LINETYPE:
1361  result = 0;
1362  break;
1363  case TRIANGLETYPE:
1364  result = 1;
1365  break;
1366  case POLYGONTYPE:
1367  result = ((LWPOLY *)geom)->nrings;
1368  break;
1369  case CURVEPOLYTYPE:
1370  result = ((LWCURVEPOLY *)geom)->nrings;
1371  break;
1372  case MULTISURFACETYPE:
1373  case MULTIPOLYGONTYPE:
1374  case POLYHEDRALSURFACETYPE:
1375  case TINTYPE:
1376  case COLLECTIONTYPE:
1377  {
1378  LWCOLLECTION *col = (LWCOLLECTION*)geom;
1379  uint32_t i = 0;
1380  for( i = 0; i < col->ngeoms; i++ )
1381  result += lwgeom_count_rings(col->geoms[i]);
1382  break;
1383  }
1384  default:
1385  lwerror("lwgeom_count_rings: unsupported input geometry type: %s", lwtype_name(geom->type));
1386  break;
1387  }
1388  LWDEBUGF(3, "counted %d rings", result);
1389  return result;
1390 }
#define LINETYPE
Definition: liblwgeom.h:85
#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
#define TRIANGLETYPE
Definition: liblwgeom.h:97
#define POLYHEDRALSURFACETYPE
Definition: liblwgeom.h:96
uint32_t ngeoms
Definition: liblwgeom.h:506
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
LWGEOM ** geoms
Definition: liblwgeom.h:508
#define TINTYPE
Definition: liblwgeom.h:98
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:1392
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:89
#define MULTISURFACETYPE
Definition: liblwgeom.h:95
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:84
uint8_t type
Definition: liblwgeom.h:395
#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
uint32_t lwgeom_count_rings(const LWGEOM *geom)
Count rings in an LWGEOM.
Definition: lwgeom.c:1344
#define COLLECTIONTYPE
Definition: liblwgeom.h:90
Here is the call graph for this function:
Here is the caller graph for this function: