PostGIS  3.4.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 1356 of file lwgeom.c.

1357 {
1358  int result = 0;
1359 
1360  /* Null? Empty? Zero. */
1361  if( ! geom || lwgeom_is_empty(geom) )
1362  return 0;
1363 
1364  switch (geom->type)
1365  {
1366  case POINTTYPE:
1367  case CIRCSTRINGTYPE:
1368  case COMPOUNDTYPE:
1369  case MULTICURVETYPE:
1370  case MULTIPOINTTYPE:
1371  case MULTILINETYPE:
1372  case LINETYPE:
1373  result = 0;
1374  break;
1375  case TRIANGLETYPE:
1376  result = 1;
1377  break;
1378  case POLYGONTYPE:
1379  result = ((LWPOLY *)geom)->nrings;
1380  break;
1381  case CURVEPOLYTYPE:
1382  result = ((LWCURVEPOLY *)geom)->nrings;
1383  break;
1384  case MULTISURFACETYPE:
1385  case MULTIPOLYGONTYPE:
1386  case POLYHEDRALSURFACETYPE:
1387  case TINTYPE:
1388  case COLLECTIONTYPE:
1389  {
1390  LWCOLLECTION *col = (LWCOLLECTION*)geom;
1391  uint32_t i = 0;
1392  for( i = 0; i < col->ngeoms; i++ )
1393  result += lwgeom_count_rings(col->geoms[i]);
1394  break;
1395  }
1396  default:
1397  lwerror("lwgeom_count_rings: unsupported input geometry type: %s", lwtype_name(geom->type));
1398  break;
1399  }
1400  LWDEBUGF(3, "counted %d rings", result);
1401  return result;
1402 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:262
#define COLLECTIONTYPE
Definition: liblwgeom.h:108
#define COMPOUNDTYPE
Definition: liblwgeom.h:110
#define CURVEPOLYTYPE
Definition: liblwgeom.h:111
#define MULTILINETYPE
Definition: liblwgeom.h:106
#define MULTISURFACETYPE
Definition: liblwgeom.h:113
#define LINETYPE
Definition: liblwgeom.h:103
#define MULTIPOINTTYPE
Definition: liblwgeom.h:105
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:102
#define TINTYPE
Definition: liblwgeom.h:116
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:107
#define POLYGONTYPE
Definition: liblwgeom.h:104
#define POLYHEDRALSURFACETYPE
Definition: liblwgeom.h:114
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:109
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:112
#define TRIANGLETYPE
Definition: liblwgeom.h:115
uint32_t lwgeom_count_rings(const LWGEOM *geom)
Count rings in an LWGEOM.
Definition: lwgeom.c:1356
#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:203
uint32_t ngeoms
Definition: liblwgeom.h:580
LWGEOM ** geoms
Definition: liblwgeom.h:575
uint8_t type
Definition: liblwgeom.h:462

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, result, 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: