PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ LWGEOM_interiorringn_polygon()

Datum LWGEOM_interiorringn_polygon ( PG_FUNCTION_ARGS  )

Definition at line 461 of file lwgeom_ogc.c.

462 {
463  GSERIALIZED *geom;
464  int32 wanted_index;
465  LWCURVEPOLY *curvepoly = NULL;
466  LWPOLY *poly = NULL;
467  POINTARRAY *ring;
468  LWLINE *line;
469  LWGEOM *lwgeom;
471  GBOX *bbox = NULL;
472  int type;
473 
474  POSTGIS_DEBUG(2, "LWGEOM_interiorringn_polygon called.");
475 
476  wanted_index = PG_GETARG_INT32(1);
477  if ( wanted_index < 1 )
478  {
479  PG_RETURN_NULL(); /* index out of range */
480  }
481 
482  geom = PG_GETARG_GSERIALIZED_P(0);
483  type = gserialized_get_type(geom);
484 
485  if ( (type != POLYGONTYPE) && (type != CURVEPOLYTYPE) )
486  {
487  PG_FREE_IF_COPY(geom, 0);
488  PG_RETURN_NULL();
489  }
490 
491  lwgeom = lwgeom_from_gserialized(geom);
492  if( lwgeom_is_empty(lwgeom) )
493  {
494  lwpoly_free(poly);
495  PG_FREE_IF_COPY(geom, 0);
496  PG_RETURN_NULL();
497  }
498 
499  if ( type == POLYGONTYPE)
500  {
502 
503  /* Ok, now we have a polygon. Let's see if it has enough holes */
504  if ( wanted_index >= (int32)poly->nrings )
505  {
506  lwpoly_free(poly);
507  PG_FREE_IF_COPY(geom, 0);
508  PG_RETURN_NULL();
509  }
510 
511  ring = poly->rings[wanted_index];
512 
513  /* COMPUTE_BBOX==TAINTING */
514  if ( poly->bbox )
515  {
516  bbox = lwalloc(sizeof(GBOX));
518  }
519 
520  /* This is a LWLINE constructed by interior ring POINTARRAY */
521  line = lwline_construct(poly->srid, bbox, ring);
522 
523 
524  result = geometry_serialize((LWGEOM *)line);
525  lwline_release(line);
526  lwpoly_free(poly);
527  }
528  else
529  {
531 
532  if (wanted_index >= (int32)curvepoly->nrings)
533  {
534  PG_FREE_IF_COPY(geom, 0);
535  lwgeom_release((LWGEOM *)curvepoly);
536  PG_RETURN_NULL();
537  }
538 
539  result = geometry_serialize(curvepoly->rings[wanted_index]);
540  lwgeom_free((LWGEOM*)curvepoly);
541  }
542 
543  PG_FREE_IF_COPY(geom, 0);
544  PG_RETURN_POINTER(result);
545 }
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:601
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:239
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:89
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1138
#define CURVEPOLYTYPE
Definition: liblwgeom.h:125
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:118
LWCURVEPOLY * lwgeom_as_lwcurvepoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:189
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:198
void lwgeom_release(LWGEOM *lwgeom)
Free the containing LWGEOM and the associated BOX.
Definition: lwgeom.c:451
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:203
type
Definition: ovdump.py:42
unsigned int int32
Definition: shpopen.c:54
LWGEOM ** rings
Definition: liblwgeom.h:617
uint32_t nrings
Definition: liblwgeom.h:622
POINTARRAY ** rings
Definition: liblwgeom.h:533
uint32_t nrings
Definition: liblwgeom.h:538
GBOX * bbox
Definition: liblwgeom.h:532
int32_t srid
Definition: liblwgeom.h:534

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: