PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ LWGEOM_exteriorring_polygon()

Datum LWGEOM_exteriorring_polygon ( PG_FUNCTION_ARGS  )

Definition at line 336 of file lwgeom_ogc.c.

337 {
338  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
339  GSERIALIZED *result;
340  POINTARRAY *extring;
341  LWGEOM *lwgeom;
342  LWLINE *line;
343  GBOX *bbox=NULL;
344  int type = gserialized_get_type(geom);
345 
346  POSTGIS_DEBUG(2, "LWGEOM_exteriorring_polygon called.");
347 
348  if ( (type != POLYGONTYPE) &&
349  (type != CURVEPOLYTYPE) &&
350  (type != TRIANGLETYPE))
351  {
352  PG_RETURN_NULL();
353  }
354 
355  lwgeom = lwgeom_from_gserialized(geom);
356 
357  if( lwgeom_is_empty(lwgeom) )
358  {
359  line = lwline_construct_empty(lwgeom->srid,
360  lwgeom_has_z(lwgeom),
361  lwgeom_has_m(lwgeom));
362  result = geometry_serialize(lwline_as_lwgeom(line));
363  }
364  else if ( type == POLYGONTYPE )
365  {
366  LWPOLY *poly = lwgeom_as_lwpoly(lwgeom);
367 
368  /* Ok, now we have a polygon. Here is its exterior ring. */
369  extring = poly->rings[0];
370 
371  /*
372  * This is a LWLINE constructed by exterior ring POINTARRAY
373  * If the input geom has a bbox, use it for
374  * the output geom, as exterior ring makes it up !
375  */
376  if ( poly->bbox )
377  bbox = gbox_copy(poly->bbox);
378 
379  line = lwline_construct(poly->srid, bbox, extring);
380  result = geometry_serialize((LWGEOM *)line);
381 
382  lwgeom_release((LWGEOM *)line);
383  }
384  else if ( type == TRIANGLETYPE )
385  {
386  LWTRIANGLE *triangle = lwgeom_as_lwtriangle(lwgeom);
387 
388  /*
389  * This is a LWLINE constructed by exterior ring POINTARRAY
390  * If the input geom has a bbox, use it for
391  * the output geom, as exterior ring makes it up !
392  */
393  if ( triangle->bbox )
394  bbox = gbox_copy(triangle->bbox);
395  line = lwline_construct(triangle->srid, bbox, triangle->points);
396 
397  result = geometry_serialize((LWGEOM *)line);
398 
399  lwgeom_release((LWGEOM *)line);
400  }
401  else
402  {
403  LWCURVEPOLY *curvepoly = lwgeom_as_lwcurvepoly(lwgeom);
404  result = geometry_serialize(curvepoly->rings[0]);
405  }
406 
407  lwgeom_free(lwgeom);
408  PG_FREE_IF_COPY(geom, 0);
409  PG_RETURN_POINTER(result);
410 }
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:321
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:916
LWLINE * lwline_construct(int32_t srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:42
LWTRIANGLE * lwgeom_as_lwtriangle(const LWGEOM *lwgeom)
Definition: lwgeom.c:206
#define POLYGONTYPE
Definition: liblwgeom.h:118
LWCURVEPOLY * lwgeom_as_lwcurvepoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:188
#define TRIANGLETYPE
Definition: liblwgeom.h:129
LWPOLY * lwgeom_as_lwpoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:197
void lwgeom_release(LWGEOM *lwgeom)
Free the containing LWGEOM and the associated BOX.
Definition: lwgeom.c:450
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition: lwgeom.c:923
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:193
type
Definition: ovdump.py:42
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
LWGEOM ** rings
Definition: liblwgeom.h:589
int32_t srid
Definition: liblwgeom.h:446
POINTARRAY ** rings
Definition: liblwgeom.h:505
GBOX * bbox
Definition: liblwgeom.h:504
int32_t srid
Definition: liblwgeom.h:506
int32_t srid
Definition: liblwgeom.h:482
GBOX * bbox
Definition: liblwgeom.h:480
POINTARRAY * points
Definition: liblwgeom.h:481

References LWTRIANGLE::bbox, LWPOLY::bbox, CURVEPOLYTYPE, gbox_copy(), geometry_serialize(), 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, LWPOLY::rings, LWCURVEPOLY::rings, LWGEOM::srid, LWTRIANGLE::srid, LWPOLY::srid, TRIANGLETYPE, and ovdump::type.

Here is the call graph for this function: