PostGIS  2.1.10dev-r@@SVN_REVISION@@
int lwgeom_count_rings ( const LWGEOM geom)

Count rings in an LWGEOM.

Count the total number of rings in any LWGEOM.

Definition at line 1181 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, result, TINTYPE, TRIANGLETYPE, and LWGEOM::type.

Referenced by LWGEOM_nrings().

1182 {
1183  int result = 0;
1184 
1185  /* Null? Empty? Zero. */
1186  if( ! geom || lwgeom_is_empty(geom) )
1187  return 0;
1188 
1189  switch (geom->type)
1190  {
1191  case POINTTYPE:
1192  case CIRCSTRINGTYPE:
1193  case COMPOUNDTYPE:
1194  case MULTICURVETYPE:
1195  case MULTIPOINTTYPE:
1196  case MULTILINETYPE:
1197  case LINETYPE:
1198  result = 0;
1199  break;
1200  case TRIANGLETYPE:
1201  result = 1;
1202  break;
1203  case POLYGONTYPE:
1204  result = ((LWPOLY *)geom)->nrings;
1205  break;
1206  case CURVEPOLYTYPE:
1207  result = ((LWCURVEPOLY *)geom)->nrings;
1208  break;
1209  case MULTISURFACETYPE:
1210  case MULTIPOLYGONTYPE:
1211  case POLYHEDRALSURFACETYPE:
1212  case TINTYPE:
1213  case COLLECTIONTYPE:
1214  {
1215  LWCOLLECTION *col = (LWCOLLECTION*)geom;
1216  int i = 0;
1217  for( i = 0; i < col->ngeoms; i++ )
1218  result += lwgeom_count_rings(col->geoms[i]);
1219  break;
1220  }
1221  default:
1222  lwerror("lwgeom_count_rings: unsupported input geometry type: %s", lwtype_name(geom->type));
1223  break;
1224  }
1225  LWDEBUGF(3, "counted %d rings", result);
1226  return result;
1227 }
#define LINETYPE
Definition: liblwgeom.h:61
#define MULTICURVETYPE
Definition: liblwgeom.h:70
#define POLYGONTYPE
Definition: liblwgeom.h:62
#define CURVEPOLYTYPE
Definition: liblwgeom.h:69
#define COMPOUNDTYPE
Definition: liblwgeom.h:68
#define MULTIPOINTTYPE
Definition: liblwgeom.h:63
int lwgeom_count_rings(const LWGEOM *geom)
Count rings in an LWGEOM.
Definition: lwgeom.c:1181
#define TRIANGLETYPE
Definition: liblwgeom.h:73
#define POLYHEDRALSURFACETYPE
Definition: liblwgeom.h:72
char ** result
Definition: liblwgeom.h:218
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:164
LWGEOM ** geoms
Definition: liblwgeom.h:465
#define TINTYPE
Definition: liblwgeom.h:74
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:1229
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:65
#define MULTISURFACETYPE
Definition: liblwgeom.h:71
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:60
uint8_t type
Definition: liblwgeom.h:352
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:67
#define MULTILINETYPE
Definition: liblwgeom.h:64
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:55
#define COLLECTIONTYPE
Definition: liblwgeom.h:66

Here is the call graph for this function:

Here is the caller graph for this function: