PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ lwgeom_count_rings()

int lwgeom_count_rings ( const LWGEOM geom)

Count rings in an LWGEOM.

Count the total number of rings in any LWGEOM.

Definition at line 1298 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().

1299 {
1300  int result = 0;
1301 
1302  /* Null? Empty? Zero. */
1303  if( ! geom || lwgeom_is_empty(geom) )
1304  return 0;
1305 
1306  switch (geom->type)
1307  {
1308  case POINTTYPE:
1309  case CIRCSTRINGTYPE:
1310  case COMPOUNDTYPE:
1311  case MULTICURVETYPE:
1312  case MULTIPOINTTYPE:
1313  case MULTILINETYPE:
1314  case LINETYPE:
1315  result = 0;
1316  break;
1317  case TRIANGLETYPE:
1318  result = 1;
1319  break;
1320  case POLYGONTYPE:
1321  result = ((LWPOLY *)geom)->nrings;
1322  break;
1323  case CURVEPOLYTYPE:
1324  result = ((LWCURVEPOLY *)geom)->nrings;
1325  break;
1326  case MULTISURFACETYPE:
1327  case MULTIPOLYGONTYPE:
1328  case POLYHEDRALSURFACETYPE:
1329  case TINTYPE:
1330  case COLLECTIONTYPE:
1331  {
1332  LWCOLLECTION *col = (LWCOLLECTION*)geom;
1333  int i = 0;
1334  for( i = 0; i < col->ngeoms; i++ )
1335  result += lwgeom_count_rings(col->geoms[i]);
1336  break;
1337  }
1338  default:
1339  lwerror("lwgeom_count_rings: unsupported input geometry type: %s", lwtype_name(geom->type));
1340  break;
1341  }
1342  LWDEBUGF(3, "counted %d rings", result);
1343  return result;
1344 }
#define LINETYPE
Definition: liblwgeom.h:86
#define MULTICURVETYPE
Definition: liblwgeom.h:95
#define POLYGONTYPE
Definition: liblwgeom.h:87
#define CURVEPOLYTYPE
Definition: liblwgeom.h:94
#define COMPOUNDTYPE
Definition: liblwgeom.h:93
#define MULTIPOINTTYPE
Definition: liblwgeom.h:88
int lwgeom_count_rings(const LWGEOM *geom)
Count rings in an LWGEOM.
Definition: lwgeom.c:1298
#define TRIANGLETYPE
Definition: liblwgeom.h:98
#define POLYHEDRALSURFACETYPE
Definition: liblwgeom.h:97
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:509
#define TINTYPE
Definition: liblwgeom.h:99
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:1346
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:90
#define MULTISURFACETYPE
Definition: liblwgeom.h:96
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:85
uint8_t type
Definition: liblwgeom.h:396
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:92
#define MULTILINETYPE
Definition: liblwgeom.h:89
#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
#define COLLECTIONTYPE
Definition: liblwgeom.h:91
Here is the call graph for this function:
Here is the caller graph for this function: