PostGIS  2.4.9dev-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 >= 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 >= 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:547
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:535
#define POLYGONTYPE
Definition: liblwgeom.h:87
#define CURVEPOLYTYPE
Definition: liblwgeom.h:94
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1099
LWCURVEPOLY * lwgeom_as_lwcurvepoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:165
GBOX * bbox
Definition: liblwgeom.h:453
LWPOLY * lwgeom_as_lwpoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:174
void lwpoly_free(LWPOLY *poly)
Definition: lwpoly.c:174
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:42
POINTARRAY ** rings
Definition: liblwgeom.h:457
int nrings
Definition: liblwgeom.h:455
int32_t srid
Definition: liblwgeom.h:454
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
void lwgeom_release(LWGEOM *lwgeom)
Free the containing LWGEOM and the associated BOX.
Definition: lwgeom.c:421
type
Definition: ovdump.py:41
void * lwalloc(size_t size)
Definition: lwutil.c:229
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:1346
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: