PostGIS  2.3.7dev-r@@SVN_REVISION@@
Datum LWGEOM_interiorringn_polygon ( PG_FUNCTION_ARGS  )

Definition at line 447 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_release(), lwline_construct(), lwline_release(), lwpoly_free(), LWPOLY::nrings, LWCURVEPOLY::nrings, POLYGONTYPE, ptarray_calculate_gbox_cartesian(), LWPOLY::rings, LWCURVEPOLY::rings, and LWPOLY::srid.

448 {
449  GSERIALIZED *geom;
450  int32 wanted_index;
451  LWCURVEPOLY *curvepoly = NULL;
452  LWPOLY *poly = NULL;
453  POINTARRAY *ring;
454  LWLINE *line;
455  LWGEOM *lwgeom;
456  GSERIALIZED *result;
457  GBOX *bbox = NULL;
458  int type;
459 
460  POSTGIS_DEBUG(2, "LWGEOM_interierringn_polygon called.");
461 
462  wanted_index = PG_GETARG_INT32(1);
463  if ( wanted_index < 1 )
464  {
465  /* elog(ERROR, "InteriorRingN: ring number is 1-based"); */
466  PG_RETURN_NULL(); /* index out of range */
467  }
468 
469  geom = PG_GETARG_GSERIALIZED_P(0);
470  type = gserialized_get_type(geom);
471 
472  if ( (type != POLYGONTYPE) && (type != CURVEPOLYTYPE) )
473  {
474  elog(ERROR, "InteriorRingN: geom is not a polygon");
475  PG_FREE_IF_COPY(geom, 0);
476  PG_RETURN_NULL();
477  }
478 
479  lwgeom = lwgeom_from_gserialized(geom);
480  if( lwgeom_is_empty(lwgeom) )
481  {
482  lwpoly_free(poly);
483  PG_FREE_IF_COPY(geom, 0);
484  PG_RETURN_NULL();
485  }
486 
487  if ( type == POLYGONTYPE)
488  {
490 
491  /* Ok, now we have a polygon. Let's see if it has enough holes */
492  if ( wanted_index >= poly->nrings )
493  {
494  lwpoly_free(poly);
495  PG_FREE_IF_COPY(geom, 0);
496  PG_RETURN_NULL();
497  }
498 
499  ring = poly->rings[wanted_index];
500 
501  /* COMPUTE_BBOX==TAINTING */
502  if ( poly->bbox )
503  {
504  bbox = lwalloc(sizeof(GBOX));
506  }
507 
508  /* This is a LWLINE constructed by interior ring POINTARRAY */
509  line = lwline_construct(poly->srid, bbox, ring);
510 
511 
512  result = geometry_serialize((LWGEOM *)line);
513  lwline_release(line);
514  lwpoly_free(poly);
515  }
516  else
517  {
519 
520  if (wanted_index >= curvepoly->nrings)
521  {
522  PG_FREE_IF_COPY(geom, 0);
523  lwgeom_release((LWGEOM *)curvepoly);
524  PG_RETURN_NULL();
525  }
526 
527  result = geometry_serialize(curvepoly->rings[wanted_index]);
528  lwgeom_free((LWGEOM*)curvepoly);
529  }
530 
531  PG_FREE_IF_COPY(geom, 0);
532  PG_RETURN_POINTER(result);
533 }
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:69
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:534
#define POLYGONTYPE
Definition: liblwgeom.h:86
#define CURVEPOLYTYPE
Definition: liblwgeom.h:93
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1063
LWCURVEPOLY * lwgeom_as_lwcurvepoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:129
GBOX * bbox
Definition: liblwgeom.h:452
LWPOLY * lwgeom_as_lwpoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:138
void lwpoly_free(LWPOLY *poly)
Definition: lwpoly.c:150
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:42
POINTARRAY ** rings
Definition: liblwgeom.h:456
int nrings
Definition: liblwgeom.h:454
int32_t srid
Definition: liblwgeom.h:453
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
void lwgeom_release(LWGEOM *lwgeom)
Free the containing LWGEOM and the associated BOX.
Definition: lwgeom.c:385
void * lwalloc(size_t size)
Definition: lwutil.c:227
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:1310
void lwline_release(LWLINE *lwline)
Definition: lwline.c:134

Here is the call graph for this function: