PostGIS  3.6.1dev-r@@SVN_REVISION@@

◆ LWGEOM_interiorringn_polygon()

Datum LWGEOM_interiorringn_polygon ( PG_FUNCTION_ARGS  )

Definition at line 599 of file lwgeom_ogc.c.

600 {
601  GSERIALIZED *geom;
602  int32 wanted_index;
603  LWCURVEPOLY *curvepoly = NULL;
604  LWPOLY *poly = NULL;
605  POINTARRAY *ring;
606  LWLINE *line;
607  LWGEOM *lwgeom;
609  GBOX *bbox = NULL;
610  int type;
611 
612  POSTGIS_DEBUG(2, "LWGEOM_interiorringn_polygon called.");
613 
614  wanted_index = PG_GETARG_INT32(1);
615  if ( wanted_index < 1 )
616  {
617  PG_RETURN_NULL(); /* index out of range */
618  }
619 
620  geom = PG_GETARG_GSERIALIZED_P(0);
621  type = gserialized_get_type(geom);
622 
623  if ( (type != POLYGONTYPE) && (type != CURVEPOLYTYPE) )
624  {
625  PG_FREE_IF_COPY(geom, 0);
626  PG_RETURN_NULL();
627  }
628 
629  lwgeom = lwgeom_from_gserialized(geom);
630  if( lwgeom_is_empty(lwgeom) )
631  {
632  lwpoly_free(poly);
633  PG_FREE_IF_COPY(geom, 0);
634  PG_RETURN_NULL();
635  }
636 
637  if ( type == POLYGONTYPE)
638  {
640 
641  /* Ok, now we have a polygon. Let's see if it has enough holes */
642  if ( wanted_index >= (int32)poly->nrings )
643  {
644  lwpoly_free(poly);
645  PG_FREE_IF_COPY(geom, 0);
646  PG_RETURN_NULL();
647  }
648 
649  ring = poly->rings[wanted_index];
650 
651  /* COMPUTE_BBOX==TAINTING */
652  if ( poly->bbox )
653  {
654  bbox = lwalloc(sizeof(GBOX));
656  }
657 
658  /* This is a LWLINE constructed by interior ring POINTARRAY */
659  line = lwline_construct(poly->srid, bbox, ring);
660 
661 
662  result = geometry_serialize((LWGEOM *)line);
663  lwline_release(line);
664  lwpoly_free(poly);
665  }
666  else
667  {
669 
670  if (wanted_index >= (int32)curvepoly->nrings)
671  {
672  PG_FREE_IF_COPY(geom, 0);
673  lwgeom_release((LWGEOM *)curvepoly);
674  PG_RETURN_NULL();
675  }
676 
677  result = geometry_serialize(curvepoly->rings[wanted_index]);
678  lwgeom_free((LWGEOM*)curvepoly);
679  }
680 
681  PG_FREE_IF_COPY(geom, 0);
682  PG_RETURN_POINTER(result);
683 }
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: