PostGIS  3.0.0dev-r@@SVN_REVISION@@

◆ LWGEOM_interiorringn_polygon()

Datum LWGEOM_interiorringn_polygon ( PG_FUNCTION_ARGS  )

Definition at line 452 of file lwgeom_ogc.c.

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_pointn_linestring(), lwgeom_release(), lwline_construct(), lwline_release(), lwpoly_free(), LWPOLY::nrings, LWCURVEPOLY::nrings, PG_FUNCTION_INFO_V1(), POLYGONTYPE, ptarray_calculate_gbox_cartesian(), LWPOLY::rings, LWCURVEPOLY::rings, LWPOLY::srid, and ovdump::type.

Referenced by LWGEOM_numinteriorrings_polygon().

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