PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ LWGEOM_interiorringn_polygon()

Datum LWGEOM_interiorringn_polygon ( PG_FUNCTION_ARGS  )

Definition at line 605 of file lwgeom_ogc.c.

606 {
607  GSERIALIZED *geom;
608  int32 wanted_index;
609  LWCURVEPOLY *curvepoly = NULL;
610  LWPOLY *poly = NULL;
611  POINTARRAY *ring;
612  LWLINE *line;
613  LWGEOM *lwgeom;
615  GBOX *bbox = NULL;
616  int type;
617 
618  POSTGIS_DEBUG(2, "LWGEOM_interiorringn_polygon called.");
619 
620  wanted_index = PG_GETARG_INT32(1);
621  if ( wanted_index < 1 )
622  {
623  PG_RETURN_NULL(); /* index out of range */
624  }
625 
626  geom = PG_GETARG_GSERIALIZED_P(0);
627  type = gserialized_get_type(geom);
628 
629  if ( (type != POLYGONTYPE) && (type != CURVEPOLYTYPE) )
630  {
631  PG_FREE_IF_COPY(geom, 0);
632  PG_RETURN_NULL();
633  }
634 
635  lwgeom = lwgeom_from_gserialized(geom);
636  if( lwgeom_is_empty(lwgeom) )
637  {
638  lwpoly_free(poly);
639  PG_FREE_IF_COPY(geom, 0);
640  PG_RETURN_NULL();
641  }
642 
643  if ( type == POLYGONTYPE)
644  {
646 
647  /* Ok, now we have a polygon. Let's see if it has enough holes */
648  if ( wanted_index >= (int32)poly->nrings )
649  {
650  lwpoly_free(poly);
651  PG_FREE_IF_COPY(geom, 0);
652  PG_RETURN_NULL();
653  }
654 
655  ring = poly->rings[wanted_index];
656 
657  /* COMPUTE_BBOX==TAINTING */
658  if ( poly->bbox )
659  {
660  bbox = lwalloc(sizeof(GBOX));
662  }
663 
664  /* This is a LWLINE constructed by interior ring POINTARRAY */
665  line = lwline_construct(poly->srid, bbox, ring);
666 
667 
668  result = geometry_serialize((LWGEOM *)line);
669  lwline_release(line);
670  lwpoly_free(poly);
671  }
672  else
673  {
675 
676  if (wanted_index >= (int32)curvepoly->nrings)
677  {
678  PG_FREE_IF_COPY(geom, 0);
679  lwgeom_release((LWGEOM *)curvepoly);
680  PG_RETURN_NULL();
681  }
682 
683  result = geometry_serialize(curvepoly->rings[wanted_index]);
684  lwgeom_free((LWGEOM*)curvepoly);
685  }
686 
687  PG_FREE_IF_COPY(geom, 0);
688  PG_RETURN_POINTER(result);
689 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:267
int ptarray_calculate_gbox_cartesian(const POINTARRAY *pa, GBOX *gbox)
Calculate box (x/y) and add values to gbox.
Definition: gbox.c:613
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:268
uint32_t gserialized_get_type(const GSERIALIZED *g)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
Definition: gserialized.c:118
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1218
#define CURVEPOLYTYPE
Definition: liblwgeom.h:111
void lwline_release(LWLINE *lwline)
Definition: lwline.c:125
LWLINE * lwline_construct(int32_t srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:42
#define POLYGONTYPE
Definition: liblwgeom.h:104
LWCURVEPOLY * lwgeom_as_lwcurvepoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:206
void * lwalloc(size_t size)
Definition: lwutil.c:227
void lwpoly_free(LWPOLY *poly)
Definition: lwpoly.c:175
LWPOLY * lwgeom_as_lwpoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:215
void lwgeom_release(LWGEOM *lwgeom)
Free the containing LWGEOM and the associated BOX.
Definition: lwgeom.c:468
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
unsigned int int32
Definition: shpopen.c:54
LWGEOM ** rings
Definition: liblwgeom.h:603
uint32_t nrings
Definition: liblwgeom.h:608
POINTARRAY ** rings
Definition: liblwgeom.h:519
uint32_t nrings
Definition: liblwgeom.h:524
GBOX * bbox
Definition: liblwgeom.h:518
int32_t srid
Definition: liblwgeom.h:520

References LWPOLY::bbox, CURVEPOLYTYPE, gserialized_get_type(), lwalloc(), lwgeom_as_lwcurvepoly(), lwgeom_as_lwpoly(), lwgeom_free(), lwgeom_from_gserialized(), lwgeom_is_empty(), lwgeom_release(), lwline_construct(), lwline_release(), lwpoly_free(), LWPOLY::nrings, LWCURVEPOLY::nrings, POLYGONTYPE, ptarray_calculate_gbox_cartesian(), result, LWPOLY::rings, LWCURVEPOLY::rings, LWPOLY::srid, and ovdump::type.

Here is the call graph for this function: