PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ LWGEOM_interiorringn_polygon()

Datum LWGEOM_interiorringn_polygon ( PG_FUNCTION_ARGS  )

Definition at line 433 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().

434 {
435  GSERIALIZED *geom;
436  int32 wanted_index;
437  LWCURVEPOLY *curvepoly = NULL;
438  LWPOLY *poly = NULL;
439  POINTARRAY *ring;
440  LWLINE *line;
441  LWGEOM *lwgeom;
442  GSERIALIZED *result;
443  GBOX *bbox = NULL;
444  int type;
445 
446  POSTGIS_DEBUG(2, "LWGEOM_interierringn_polygon called.");
447 
448  wanted_index = PG_GETARG_INT32(1);
449  if ( wanted_index < 1 )
450  {
451  /* elog(ERROR, "InteriorRingN: ring number is 1-based"); */
452  PG_RETURN_NULL(); /* index out of range */
453  }
454 
455  geom = PG_GETARG_GSERIALIZED_P(0);
456  type = gserialized_get_type(geom);
457 
458  if ( (type != POLYGONTYPE) && (type != CURVEPOLYTYPE) )
459  {
460  elog(ERROR, "InteriorRingN: geom is not a polygon");
461  PG_FREE_IF_COPY(geom, 0);
462  PG_RETURN_NULL();
463  }
464 
465  lwgeom = lwgeom_from_gserialized(geom);
466  if( lwgeom_is_empty(lwgeom) )
467  {
468  lwpoly_free(poly);
469  PG_FREE_IF_COPY(geom, 0);
470  PG_RETURN_NULL();
471  }
472 
473  if ( type == POLYGONTYPE)
474  {
476 
477  /* Ok, now we have a polygon. Let's see if it has enough holes */
478  if ( wanted_index >= poly->nrings )
479  {
480  lwpoly_free(poly);
481  PG_FREE_IF_COPY(geom, 0);
482  PG_RETURN_NULL();
483  }
484 
485  ring = poly->rings[wanted_index];
486 
487  /* COMPUTE_BBOX==TAINTING */
488  if ( poly->bbox )
489  {
490  bbox = lwalloc(sizeof(GBOX));
492  }
493 
494  /* This is a LWLINE constructed by interior ring POINTARRAY */
495  line = lwline_construct(poly->srid, bbox, ring);
496 
497 
498  result = geometry_serialize((LWGEOM *)line);
499  lwline_release(line);
500  lwpoly_free(poly);
501  }
502  else
503  {
505 
506  if (wanted_index >= curvepoly->nrings)
507  {
508  PG_FREE_IF_COPY(geom, 0);
509  lwgeom_release((LWGEOM *)curvepoly);
510  PG_RETURN_NULL();
511  }
512 
513  result = geometry_serialize(curvepoly->rings[wanted_index]);
514  lwgeom_free((LWGEOM*)curvepoly);
515  }
516 
517  PG_FREE_IF_COPY(geom, 0);
518  PG_RETURN_POINTER(result);
519 }
int ptarray_calculate_gbox_cartesian(const POINTARRAY *pa, GBOX *gbox)
Calculate box (x/y) and add values to gbox.
Definition: g_box.c:512
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:55
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:519
#define POLYGONTYPE
Definition: liblwgeom.h:72
#define CURVEPOLYTYPE
Definition: liblwgeom.h:79
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1050
LWCURVEPOLY * lwgeom_as_lwcurvepoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:116
GBOX * bbox
Definition: liblwgeom.h:437
LWPOLY * lwgeom_as_lwpoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:125
void lwpoly_free(LWPOLY *poly)
Definition: lwpoly.c:79
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:29
POINTARRAY ** rings
Definition: liblwgeom.h:441
int nrings
Definition: liblwgeom.h:439
int32_t srid
Definition: liblwgeom.h:438
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
void lwgeom_release(LWGEOM *lwgeom)
Free the containing LWGEOM and the associated BOX.
Definition: lwgeom.c:372
type
Definition: ovdump.py:41
void * lwalloc(size_t size)
Definition: lwutil.c:199
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:1297
void lwline_release(LWLINE *lwline)
Definition: lwline.c:121
Here is the call graph for this function:
Here is the caller graph for this function: