PostGIS  2.3.8dev-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 1262 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().

1263 {
1264  int result = 0;
1265 
1266  /* Null? Empty? Zero. */
1267  if( ! geom || lwgeom_is_empty(geom) )
1268  return 0;
1269 
1270  switch (geom->type)
1271  {
1272  case POINTTYPE:
1273  case CIRCSTRINGTYPE:
1274  case COMPOUNDTYPE:
1275  case MULTICURVETYPE:
1276  case MULTIPOINTTYPE:
1277  case MULTILINETYPE:
1278  case LINETYPE:
1279  result = 0;
1280  break;
1281  case TRIANGLETYPE:
1282  result = 1;
1283  break;
1284  case POLYGONTYPE:
1285  result = ((LWPOLY *)geom)->nrings;
1286  break;
1287  case CURVEPOLYTYPE:
1288  result = ((LWCURVEPOLY *)geom)->nrings;
1289  break;
1290  case MULTISURFACETYPE:
1291  case MULTIPOLYGONTYPE:
1292  case POLYHEDRALSURFACETYPE:
1293  case TINTYPE:
1294  case COLLECTIONTYPE:
1295  {
1296  LWCOLLECTION *col = (LWCOLLECTION*)geom;
1297  int i = 0;
1298  for( i = 0; i < col->ngeoms; i++ )
1299  result += lwgeom_count_rings(col->geoms[i]);
1300  break;
1301  }
1302  default:
1303  lwerror("lwgeom_count_rings: unsupported input geometry type: %s", lwtype_name(geom->type));
1304  break;
1305  }
1306  LWDEBUGF(3, "counted %d rings", result);
1307  return result;
1308 }
#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
int lwgeom_count_rings(const LWGEOM *geom)
Count rings in an LWGEOM.
Definition: lwgeom.c:1262
#define TRIANGLETYPE
Definition: liblwgeom.h:97
#define POLYHEDRALSURFACETYPE
Definition: liblwgeom.h:96
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:216
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:1310
#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:102
#define COLLECTIONTYPE
Definition: liblwgeom.h:90
Here is the call graph for this function:
Here is the caller graph for this function: