PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ LWGEOM_interiorringn_polygon()

Datum LWGEOM_interiorringn_polygon ( PG_FUNCTION_ARGS  )

Definition at line 453 of file lwgeom_ogc.c.

454 {
455  GSERIALIZED *geom;
456  int32 wanted_index;
457  LWCURVEPOLY *curvepoly = NULL;
458  LWPOLY *poly = NULL;
459  POINTARRAY *ring;
460  LWLINE *line;
461  LWGEOM *lwgeom;
462  GSERIALIZED *result;
463  GBOX *bbox = NULL;
464  int type;
465 
466  POSTGIS_DEBUG(2, "LWGEOM_interiorringn_polygon called.");
467 
468  wanted_index = PG_GETARG_INT32(1);
469  if ( wanted_index < 1 )
470  {
471  PG_RETURN_NULL(); /* index out of range */
472  }
473 
474  geom = PG_GETARG_GSERIALIZED_P(0);
475  type = gserialized_get_type(geom);
476 
477  if ( (type != POLYGONTYPE) && (type != CURVEPOLYTYPE) )
478  {
479  PG_FREE_IF_COPY(geom, 0);
480  PG_RETURN_NULL();
481  }
482 
483  lwgeom = lwgeom_from_gserialized(geom);
484  if( lwgeom_is_empty(lwgeom) )
485  {
486  lwpoly_free(poly);
487  PG_FREE_IF_COPY(geom, 0);
488  PG_RETURN_NULL();
489  }
490 
491  if ( type == POLYGONTYPE)
492  {
494 
495  /* Ok, now we have a polygon. Let's see if it has enough holes */
496  if ( wanted_index >= (int32)poly->nrings )
497  {
498  lwpoly_free(poly);
499  PG_FREE_IF_COPY(geom, 0);
500  PG_RETURN_NULL();
501  }
502 
503  ring = poly->rings[wanted_index];
504 
505  /* COMPUTE_BBOX==TAINTING */
506  if ( poly->bbox )
507  {
508  bbox = lwalloc(sizeof(GBOX));
510  }
511 
512  /* This is a LWLINE constructed by interior ring POINTARRAY */
513  line = lwline_construct(poly->srid, bbox, ring);
514 
515 
516  result = geometry_serialize((LWGEOM *)line);
517  lwline_release(line);
518  lwpoly_free(poly);
519  }
520  else
521  {
523 
524  if (wanted_index >= (int32)curvepoly->nrings)
525  {
526  PG_FREE_IF_COPY(geom, 0);
527  lwgeom_release((LWGEOM *)curvepoly);
528  PG_RETURN_NULL();
529  }
530 
531  result = geometry_serialize(curvepoly->rings[wanted_index]);
532  lwgeom_free((LWGEOM*)curvepoly);
533  }
534 
535  PG_FREE_IF_COPY(geom, 0);
536  PG_RETURN_POINTER(result);
537 }
int ptarray_calculate_gbox_cartesian(const POINTARRAY *pa, GBOX *gbox)
Calculate box (x/y) and add values to gbox.
Definition: g_box.c:542
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
uint32_t gserialized_get_type(const GSERIALIZED *s)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
Definition: g_serialized.c:86
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
#define CURVEPOLYTYPE
Definition: liblwgeom.h:94
void lwline_release(LWLINE *lwline)
Definition: lwline.c:134
#define POLYGONTYPE
Definition: liblwgeom.h:87
LWCURVEPOLY * lwgeom_as_lwcurvepoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:197
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition: lwgeom.c:1393
void * lwalloc(size_t size)
Definition: lwutil.c:229
void lwpoly_free(LWPOLY *poly)
Definition: lwpoly.c:175
LWPOLY * lwgeom_as_lwpoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:206
void lwgeom_release(LWGEOM *lwgeom)
Free the containing LWGEOM and the associated BOX.
Definition: lwgeom.c:459
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:42
type
Definition: ovdump.py:41
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
unsigned int int32
Definition: shpopen.c:273
LWGEOM ** rings
Definition: liblwgeom.h:538
uint32_t nrings
Definition: liblwgeom.h:536
POINTARRAY ** rings
Definition: liblwgeom.h:460
uint32_t nrings
Definition: liblwgeom.h:458
GBOX * bbox
Definition: liblwgeom.h:456
int32_t srid
Definition: liblwgeom.h:457

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: