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

Definition at line 438 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(), result, LWPOLY::rings, LWCURVEPOLY::rings, and LWPOLY::srid.

439 {
440  GSERIALIZED *geom;
441  int32 wanted_index;
442  LWCURVEPOLY *curvepoly = NULL;
443  LWPOLY *poly = NULL;
444  POINTARRAY *ring;
445  LWLINE *line;
446  LWGEOM *lwgeom;
448  GBOX *bbox = NULL;
449  int type;
450 
451  POSTGIS_DEBUG(2, "LWGEOM_interierringn_polygon called.");
452 
453  wanted_index = PG_GETARG_INT32(1);
454  if ( wanted_index < 1 )
455  {
456  /* elog(ERROR, "InteriorRingN: ring number is 1-based"); */
457  PG_RETURN_NULL(); /* index out of range */
458  }
459 
460  geom = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
461  type = gserialized_get_type(geom);
462 
463  if ( (type != POLYGONTYPE) && (type != CURVEPOLYTYPE) )
464  {
465  elog(ERROR, "InteriorRingN: geom is not a polygon");
466  PG_FREE_IF_COPY(geom, 0);
467  PG_RETURN_NULL();
468  }
469 
470  lwgeom = lwgeom_from_gserialized(geom);
471  if( lwgeom_is_empty(lwgeom) )
472  {
473  lwpoly_free(poly);
474  PG_FREE_IF_COPY(geom, 0);
475  PG_RETURN_NULL();
476  }
477 
478  if ( type == POLYGONTYPE)
479  {
481 
482  /* Ok, now we have a polygon. Let's see if it has enough holes */
483  if ( wanted_index >= poly->nrings )
484  {
485  lwpoly_free(poly);
486  PG_FREE_IF_COPY(geom, 0);
487  PG_RETURN_NULL();
488  }
489 
490  ring = poly->rings[wanted_index];
491 
492  /* COMPUTE_BBOX==TAINTING */
493  if ( poly->bbox )
494  {
495  bbox = lwalloc(sizeof(GBOX));
497  }
498 
499  /* This is a LWLINE constructed by interior ring POINTARRAY */
500  line = lwline_construct(poly->srid, bbox, ring);
501 
502 
503  result = geometry_serialize((LWGEOM *)line);
504  lwline_release(line);
505  lwpoly_free(poly);
506  }
507  else
508  {
510 
511  if (wanted_index >= curvepoly->nrings)
512  {
513  PG_FREE_IF_COPY(geom, 0);
514  lwgeom_release((LWGEOM *)curvepoly);
515  PG_RETURN_NULL();
516  }
517 
518  result = geometry_serialize(curvepoly->rings[wanted_index]);
519  lwgeom_free((LWGEOM*)curvepoly);
520  }
521 
522  PG_FREE_IF_COPY(geom, 0);
523  PG_RETURN_POINTER(result);
524 }
int ptarray_calculate_gbox_cartesian(const POINTARRAY *pa, GBOX *gbox)
Calculate box (x/y) and add values to gbox.
Definition: g_box.c:471
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:56
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
LWGEOM ** rings
Definition: liblwgeom.h:491
#define POLYGONTYPE
Definition: liblwgeom.h:62
#define CURVEPOLYTYPE
Definition: liblwgeom.h:69
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1006
LWCURVEPOLY * lwgeom_as_lwcurvepoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:116
GBOX * bbox
Definition: liblwgeom.h:409
LWPOLY * lwgeom_as_lwpoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:125
char ** result
Definition: liblwgeom.h:218
LWGEOM * geom
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:413
int nrings
Definition: liblwgeom.h:411
int32_t srid
Definition: liblwgeom.h:410
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
void lwgeom_release(LWGEOM *lwgeom)
Free the containing LWGEOM and the associated BOX.
Definition: lwgeom.c:328
void * lwalloc(size_t size)
Definition: lwutil.c:175
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:1229
void lwline_release(LWLINE *lwline)
Definition: lwline.c:121

Here is the call graph for this function: