PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ LWGEOM_exteriorring_polygon()

Datum LWGEOM_exteriorring_polygon ( PG_FUNCTION_ARGS  )

Definition at line 337 of file lwgeom_ogc.c.

338 {
339  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
341  POINTARRAY *extring;
342  LWGEOM *lwgeom;
343  LWLINE *line;
344  GBOX *bbox=NULL;
345  int type = gserialized_get_type(geom);
346 
347  POSTGIS_DEBUG(2, "LWGEOM_exteriorring_polygon called.");
348 
349  if ( (type != POLYGONTYPE) &&
350  (type != CURVEPOLYTYPE) &&
351  (type != TRIANGLETYPE))
352  {
353  PG_RETURN_NULL();
354  }
355 
356  lwgeom = lwgeom_from_gserialized(geom);
357 
358  if( lwgeom_is_empty(lwgeom) )
359  {
360  line = lwline_construct_empty(lwgeom->srid,
361  lwgeom_has_z(lwgeom),
362  lwgeom_has_m(lwgeom));
363  result = geometry_serialize(lwline_as_lwgeom(line));
364  }
365  else if ( type == POLYGONTYPE )
366  {
367  LWPOLY *poly = lwgeom_as_lwpoly(lwgeom);
368 
369  /* Ok, now we have a polygon. Here is its exterior ring. */
370  extring = poly->rings[0];
371 
372  /*
373  * This is a LWLINE constructed by exterior ring POINTARRAY
374  * If the input geom has a bbox, use it for
375  * the output geom, as exterior ring makes it up !
376  */
377  if ( poly->bbox )
378  bbox = gbox_copy(poly->bbox);
379 
380  line = lwline_construct(poly->srid, bbox, extring);
381  result = geometry_serialize((LWGEOM *)line);
382 
383  lwgeom_release((LWGEOM *)line);
384  }
385  else if ( type == TRIANGLETYPE )
386  {
387  LWTRIANGLE *triangle = lwgeom_as_lwtriangle(lwgeom);
388 
389  /*
390  * This is a LWLINE constructed by exterior ring POINTARRAY
391  * If the input geom has a bbox, use it for
392  * the output geom, as exterior ring makes it up !
393  */
394  if ( triangle->bbox )
395  bbox = gbox_copy(triangle->bbox);
396  line = lwline_construct(triangle->srid, bbox, triangle->points);
397 
398  result = geometry_serialize((LWGEOM *)line);
399 
400  lwgeom_release((LWGEOM *)line);
401  }
402  else
403  {
404  LWCURVEPOLY *curvepoly = lwgeom_as_lwcurvepoly(lwgeom);
405  result = geometry_serialize(curvepoly->rings[0]);
406  }
407 
408  lwgeom_free(lwgeom);
409  PG_FREE_IF_COPY(geom, 0);
410  PG_RETURN_POINTER(result);
411 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:267
GBOX * gbox_copy(const GBOX *box)
Return a copy of the GBOX, based on dimensionality of flags.
Definition: gbox.c:426
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:239
uint32_t gserialized_get_type(const GSERIALIZED *g)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
Definition: gserialized.c:89
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition: lwgeom.c:322
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1138
#define CURVEPOLYTYPE
Definition: liblwgeom.h:125
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:917
LWLINE * lwline_construct(int32_t srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:42
LWTRIANGLE * lwgeom_as_lwtriangle(const LWGEOM *lwgeom)
Definition: lwgeom.c:207
#define POLYGONTYPE
Definition: liblwgeom.h:118
LWCURVEPOLY * lwgeom_as_lwcurvepoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:189
#define TRIANGLETYPE
Definition: liblwgeom.h:129
LWPOLY * lwgeom_as_lwpoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:198
void lwgeom_release(LWGEOM *lwgeom)
Free the containing LWGEOM and the associated BOX.
Definition: lwgeom.c:451
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition: lwgeom.c:924
LWLINE * lwline_construct_empty(int32_t srid, char hasz, char hasm)
Definition: lwline.c:55
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:203
type
Definition: ovdump.py:42
LWGEOM ** rings
Definition: liblwgeom.h:617
int32_t srid
Definition: liblwgeom.h:474
POINTARRAY ** rings
Definition: liblwgeom.h:533
GBOX * bbox
Definition: liblwgeom.h:532
int32_t srid
Definition: liblwgeom.h:534
int32_t srid
Definition: liblwgeom.h:510
GBOX * bbox
Definition: liblwgeom.h:508
POINTARRAY * points
Definition: liblwgeom.h:509

References LWTRIANGLE::bbox, LWPOLY::bbox, CURVEPOLYTYPE, gbox_copy(), gserialized_get_type(), lwgeom_as_lwcurvepoly(), lwgeom_as_lwpoly(), lwgeom_as_lwtriangle(), lwgeom_free(), lwgeom_from_gserialized(), lwgeom_has_m(), lwgeom_has_z(), lwgeom_is_empty(), lwgeom_release(), lwline_as_lwgeom(), lwline_construct(), lwline_construct_empty(), LWTRIANGLE::points, POLYGONTYPE, result, LWPOLY::rings, LWCURVEPOLY::rings, LWGEOM::srid, LWTRIANGLE::srid, LWPOLY::srid, TRIANGLETYPE, and ovdump::type.

Here is the call graph for this function: