PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ LWGEOM_interiorringn_polygon()

Datum LWGEOM_interiorringn_polygon ( PG_FUNCTION_ARGS  )

Definition at line 460 of file lwgeom_ogc.c.

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

References LWPOLY::bbox, CURVEPOLYTYPE, geometry_serialize(), 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(), LWPOLY::rings, LWCURVEPOLY::rings, LWPOLY::srid, and ovdump::type.

Here is the call graph for this function: