PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ LWGEOM_interiorringn_polygon()

Datum LWGEOM_interiorringn_polygon ( PG_FUNCTION_ARGS  )

Definition at line 466 of file lwgeom_ogc.c.

467 {
468  GSERIALIZED *geom;
469  int32 wanted_index;
470  LWCURVEPOLY *curvepoly = NULL;
471  LWPOLY *poly = NULL;
472  POINTARRAY *ring;
473  LWLINE *line;
474  LWGEOM *lwgeom;
476  GBOX *bbox = NULL;
477  int type;
478 
479  POSTGIS_DEBUG(2, "LWGEOM_interiorringn_polygon called.");
480 
481  wanted_index = PG_GETARG_INT32(1);
482  if ( wanted_index < 1 )
483  {
484  PG_RETURN_NULL(); /* index out of range */
485  }
486 
487  geom = PG_GETARG_GSERIALIZED_P(0);
488  type = gserialized_get_type(geom);
489 
490  if ( (type != POLYGONTYPE) && (type != CURVEPOLYTYPE) )
491  {
492  PG_FREE_IF_COPY(geom, 0);
493  PG_RETURN_NULL();
494  }
495 
496  lwgeom = lwgeom_from_gserialized(geom);
497  if( lwgeom_is_empty(lwgeom) )
498  {
499  lwpoly_free(poly);
500  PG_FREE_IF_COPY(geom, 0);
501  PG_RETURN_NULL();
502  }
503 
504  if ( type == POLYGONTYPE)
505  {
507 
508  /* Ok, now we have a polygon. Let's see if it has enough holes */
509  if ( wanted_index >= (int32)poly->nrings )
510  {
511  lwpoly_free(poly);
512  PG_FREE_IF_COPY(geom, 0);
513  PG_RETURN_NULL();
514  }
515 
516  ring = poly->rings[wanted_index];
517 
518  /* COMPUTE_BBOX==TAINTING */
519  if ( poly->bbox )
520  {
521  bbox = lwalloc(sizeof(GBOX));
523  }
524 
525  /* This is a LWLINE constructed by interior ring POINTARRAY */
526  line = lwline_construct(poly->srid, bbox, ring);
527 
528 
529  result = geometry_serialize((LWGEOM *)line);
530  lwline_release(line);
531  lwpoly_free(poly);
532  }
533  else
534  {
536 
537  if (wanted_index >= (int32)curvepoly->nrings)
538  {
539  PG_FREE_IF_COPY(geom, 0);
540  lwgeom_release((LWGEOM *)curvepoly);
541  PG_RETURN_NULL();
542  }
543 
544  result = geometry_serialize(curvepoly->rings[wanted_index]);
545  lwgeom_free((LWGEOM*)curvepoly);
546  }
547 
548  PG_FREE_IF_COPY(geom, 0);
549  PG_RETURN_POINTER(result);
550 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:262
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:1155
#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:203
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: