PostGIS  3.6.1dev-r@@SVN_REVISION@@

◆ LWGEOM_numinteriorrings_polygon()

Datum LWGEOM_numinteriorrings_polygon ( PG_FUNCTION_ARGS  )

Definition at line 542 of file lwgeom_ogc.c.

543 {
544  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
545  LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
546  int type = lwgeom->type;
547  int result = -1;
548 
549  if ( !lwgeom_has_rings(lwgeom) )
550  PG_RETURN_NULL();
551 
552  if ( lwgeom_is_empty(lwgeom) || type == TRIANGLETYPE )
553  PG_RETURN_INT32(0);
554 
555  /*
556  * POLYGON and TRIANGLE have same underlying structure
557  * with an array of nrings rings of POINTARRAY holding the
558  * rings
559  */
560  if (type == POLYGONTYPE )
561  {
562  const LWPOLY *poly = lwgeom_as_lwpoly(lwgeom);
563  result = poly->nrings - 1;
564  }
565  /*
566  * CURVEPOLYGON on the other hand is structured
567  * like a collection with each ring represented by
568  * a geometry in a list ngeoms long.
569  */
570  else if (type == CURVEPOLYTYPE)
571  {
572  const LWCURVEPOLY *curv = lwgeom_as_lwcurvepoly(lwgeom);
573  result = curv->nrings - 1;
574  }
575  /*
576  * If a new type is added to the zoo, we should error
577  * out.
578  */
579  else
580  {
581  elog(ERROR, "%s unsupported ring type %d", __func__, type);
582  }
583 
584  lwgeom_free(lwgeom);
585  PG_FREE_IF_COPY(geom, 0);
586  if ( result < 0 )
587  PG_RETURN_NULL();
588  else
589  PG_RETURN_INT32(result);
590 }
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: