PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ LWGEOM_exteriorring_polygon()

Datum LWGEOM_exteriorring_polygon ( PG_FUNCTION_ARGS  )

Definition at line 329 of file lwgeom_ogc.c.

330 {
331  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
332  GSERIALIZED *result;
333  POINTARRAY *extring;
334  LWGEOM *lwgeom;
335  LWLINE *line;
336  GBOX *bbox=NULL;
337  int type = gserialized_get_type(geom);
338 
339  POSTGIS_DEBUG(2, "LWGEOM_exteriorring_polygon called.");
340 
341  if ( (type != POLYGONTYPE) &&
342  (type != CURVEPOLYTYPE) &&
343  (type != TRIANGLETYPE))
344  {
345  PG_RETURN_NULL();
346  }
347 
348  lwgeom = lwgeom_from_gserialized(geom);
349 
350  if( lwgeom_is_empty(lwgeom) )
351  {
352  line = lwline_construct_empty(lwgeom->srid,
353  lwgeom_has_z(lwgeom),
354  lwgeom_has_m(lwgeom));
355  result = geometry_serialize(lwline_as_lwgeom(line));
356  }
357  else if ( type == POLYGONTYPE )
358  {
359  LWPOLY *poly = lwgeom_as_lwpoly(lwgeom);
360 
361  /* Ok, now we have a polygon. Here is its exterior ring. */
362  extring = poly->rings[0];
363 
364  /*
365  * This is a LWLINE constructed by exterior ring POINTARRAY
366  * If the input geom has a bbox, use it for
367  * the output geom, as exterior ring makes it up !
368  */
369  if ( poly->bbox )
370  bbox = gbox_copy(poly->bbox);
371 
372  line = lwline_construct(poly->srid, bbox, extring);
373  result = geometry_serialize((LWGEOM *)line);
374 
375  lwgeom_release((LWGEOM *)line);
376  }
377  else if ( type == TRIANGLETYPE )
378  {
379  LWTRIANGLE *triangle = lwgeom_as_lwtriangle(lwgeom);
380 
381  /*
382  * This is a LWLINE constructed by exterior ring POINTARRAY
383  * If the input geom has a bbox, use it for
384  * the output geom, as exterior ring makes it up !
385  */
386  if ( triangle->bbox )
387  bbox = gbox_copy(triangle->bbox);
388  line = lwline_construct(triangle->srid, bbox, triangle->points);
389 
390  result = geometry_serialize((LWGEOM *)line);
391 
392  lwgeom_release((LWGEOM *)line);
393  }
394  else
395  {
396  LWCURVEPOLY *curvepoly = lwgeom_as_lwcurvepoly(lwgeom);
397  result = geometry_serialize(curvepoly->rings[0]);
398  }
399 
400  lwgeom_free(lwgeom);
401  PG_FREE_IF_COPY(geom, 0);
402  PG_RETURN_POINTER(result);
403 }
GBOX * gbox_copy(const GBOX *box)
Return a copy of the GBOX, based on dimensionality of flags.
Definition: g_box.c:433
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
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:86
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition: lwgeom.c:330
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
#define CURVEPOLYTYPE
Definition: liblwgeom.h:94
LWLINE * lwline_construct_empty(int srid, char hasz, char hasm)
Definition: lwline.c:64
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:930
LWTRIANGLE * lwgeom_as_lwtriangle(const LWGEOM *lwgeom)
Definition: lwgeom.c:215
#define POLYGONTYPE
Definition: liblwgeom.h:87
LWCURVEPOLY * lwgeom_as_lwcurvepoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:197
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:1393
#define TRIANGLETYPE
Definition: liblwgeom.h:98
LWPOLY * lwgeom_as_lwpoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:206
void lwgeom_release(LWGEOM *lwgeom)
Free the containing LWGEOM and the associated BOX.
Definition: lwgeom.c:459
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition: lwgeom.c:937
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:42
type
Definition: ovdump.py:41
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
LWGEOM ** rings
Definition: liblwgeom.h:538
int32_t srid
Definition: liblwgeom.h:402
POINTARRAY ** rings
Definition: liblwgeom.h:460
GBOX * bbox
Definition: liblwgeom.h:456
int32_t srid
Definition: liblwgeom.h:457
int32_t srid
Definition: liblwgeom.h:435
GBOX * bbox
Definition: liblwgeom.h:434
POINTARRAY * points
Definition: liblwgeom.h:436

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: