PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ LWGEOM_numinteriorrings_polygon()

Datum LWGEOM_numinteriorrings_polygon ( PG_FUNCTION_ARGS  )

Definition at line 548 of file lwgeom_ogc.c.

549 {
550  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
551  LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
552  int type = lwgeom->type;
553  int result = -1;
554 
555  if ( !lwgeom_has_rings(lwgeom) )
556  PG_RETURN_NULL();
557 
558  if ( lwgeom_is_empty(lwgeom) || type == TRIANGLETYPE )
559  PG_RETURN_INT32(0);
560 
561  /*
562  * POLYGON and TRIANGLE have same underlying structure
563  * with an array of nrings rings of POINTARRAY holding the
564  * rings
565  */
566  if (type == POLYGONTYPE )
567  {
568  const LWPOLY *poly = lwgeom_as_lwpoly(lwgeom);
569  result = poly->nrings - 1;
570  }
571  /*
572  * CURVEPOLYGON on the other hand is structured
573  * like a collection with each ring represented by
574  * a geometry in a list ngeoms long.
575  */
576  else if (type == CURVEPOLYTYPE)
577  {
578  const LWCURVEPOLY *curv = lwgeom_as_lwcurvepoly(lwgeom);
579  result = curv->nrings - 1;
580  }
581  /*
582  * If a new type is added to the zoo, we should error
583  * out.
584  */
585  else
586  {
587  elog(ERROR, "%s unsupported ring type %d", __func__, type);
588  }
589 
590  lwgeom_free(lwgeom);
591  PG_FREE_IF_COPY(geom, 0);
592  if ( result < 0 )
593  PG_RETURN_NULL();
594  else
595  PG_RETURN_INT32(result);
596 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:267
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:268
int lwgeom_has_rings(const LWGEOM *geom)
Is this a type that has rings enclosing an area, but is not a collection of areas?...
Definition: lwgeom.c:1146
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1218
#define CURVEPOLYTYPE
Definition: liblwgeom.h:111
#define POLYGONTYPE
Definition: liblwgeom.h:104
LWCURVEPOLY * lwgeom_as_lwcurvepoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:206
#define TRIANGLETYPE
Definition: liblwgeom.h:115
LWPOLY * lwgeom_as_lwpoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:215
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition: lwinline.h:199
type
Definition: ovdump.py:42
uint32_t nrings
Definition: liblwgeom.h:608
uint8_t type
Definition: liblwgeom.h:462
uint32_t nrings
Definition: liblwgeom.h:524

References CURVEPOLYTYPE, lwgeom_as_lwcurvepoly(), lwgeom_as_lwpoly(), lwgeom_free(), lwgeom_from_gserialized(), lwgeom_has_rings(), lwgeom_is_empty(), LWPOLY::nrings, LWCURVEPOLY::nrings, POLYGONTYPE, result, TRIANGLETYPE, LWGEOM::type, and ovdump::type.

Here is the call graph for this function: