PostGIS  2.5.0dev-r@@SVN_REVISION@@
Datum LWGEOM_numinteriorrings_polygon ( PG_FUNCTION_ARGS  )

Definition at line 411 of file lwgeom_ogc.c.

References CURVEPOLYTYPE, gserialized_get_type(), lwgeom_free(), lwgeom_from_gserialized(), lwgeom_is_empty(), LWPOLY::nrings, POLYGONTYPE, and TRIANGLETYPE.

412 {
413  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
414  int type = gserialized_get_type(geom);
415  LWGEOM *lwgeom;
416  int result = -1;
417 
418  if ( (type != POLYGONTYPE) &&
419  (type != CURVEPOLYTYPE) &&
420  (type != TRIANGLETYPE))
421  {
422  PG_RETURN_NULL();
423  }
424 
425  lwgeom = lwgeom_from_gserialized(geom);
426  if ( lwgeom_is_empty(lwgeom) )
427  {
428  result = 0;
429  }
430  else
431  {
432  const LWPOLY *poly = (LWPOLY*)lwgeom;
433  result = poly->nrings - 1;
434  }
435 
436  lwgeom_free(lwgeom);
437  PG_FREE_IF_COPY(geom, 0);
438 
439  if ( result < 0 )
440  PG_RETURN_NULL();
441 
442  PG_RETURN_INT32(result);
443 }
uint32_t gserialized_get_type(const GSERIALIZED *s)
Extract the geometry type from the serialized form (it hides in the anonymous data area...
Definition: g_serialized.c:86
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
#define POLYGONTYPE
Definition: liblwgeom.h:86
#define CURVEPOLYTYPE
Definition: liblwgeom.h:93
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1137
#define TRIANGLETYPE
Definition: liblwgeom.h:97
uint32_t nrings
Definition: liblwgeom.h:454
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:1386

Here is the call graph for this function: