PostGIS  2.2.7dev-r@@SVN_REVISION@@
int 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 1249 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().

1250 {
1251  int result = 0;
1252 
1253  /* Null? Empty? Zero. */
1254  if( ! geom || lwgeom_is_empty(geom) )
1255  return 0;
1256 
1257  switch (geom->type)
1258  {
1259  case POINTTYPE:
1260  case CIRCSTRINGTYPE:
1261  case COMPOUNDTYPE:
1262  case MULTICURVETYPE:
1263  case MULTIPOINTTYPE:
1264  case MULTILINETYPE:
1265  case LINETYPE:
1266  result = 0;
1267  break;
1268  case TRIANGLETYPE:
1269  result = 1;
1270  break;
1271  case POLYGONTYPE:
1272  result = ((LWPOLY *)geom)->nrings;
1273  break;
1274  case CURVEPOLYTYPE:
1275  result = ((LWCURVEPOLY *)geom)->nrings;
1276  break;
1277  case MULTISURFACETYPE:
1278  case MULTIPOLYGONTYPE:
1279  case POLYHEDRALSURFACETYPE:
1280  case TINTYPE:
1281  case COLLECTIONTYPE:
1282  {
1283  LWCOLLECTION *col = (LWCOLLECTION*)geom;
1284  int i = 0;
1285  for( i = 0; i < col->ngeoms; i++ )
1286  result += lwgeom_count_rings(col->geoms[i]);
1287  break;
1288  }
1289  default:
1290  lwerror("lwgeom_count_rings: unsupported input geometry type: %s", lwtype_name(geom->type));
1291  break;
1292  }
1293  LWDEBUGF(3, "counted %d rings", result);
1294  return result;
1295 }
#define LINETYPE
Definition: liblwgeom.h:71
#define MULTICURVETYPE
Definition: liblwgeom.h:80
#define POLYGONTYPE
Definition: liblwgeom.h:72
#define CURVEPOLYTYPE
Definition: liblwgeom.h:79
#define COMPOUNDTYPE
Definition: liblwgeom.h:78
#define MULTIPOINTTYPE
Definition: liblwgeom.h:73
int lwgeom_count_rings(const LWGEOM *geom)
Count rings in an LWGEOM.
Definition: lwgeom.c:1249
#define TRIANGLETYPE
Definition: liblwgeom.h:83
#define POLYHEDRALSURFACETYPE
Definition: liblwgeom.h:82
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:188
LWGEOM ** geoms
Definition: liblwgeom.h:493
#define TINTYPE
Definition: liblwgeom.h:84
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:1297
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:75
#define MULTISURFACETYPE
Definition: liblwgeom.h:81
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:70
uint8_t type
Definition: liblwgeom.h:380
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:77
#define MULTILINETYPE
Definition: liblwgeom.h:74
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:55
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:74
#define COLLECTIONTYPE
Definition: liblwgeom.h:76

Here is the call graph for this function:

Here is the caller graph for this function: