PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ LWGEOM_exteriorring_polygon()

Datum LWGEOM_exteriorring_polygon ( PG_FUNCTION_ARGS  )

Definition at line 329 of file lwgeom_ogc.c.

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_numinteriorrings_polygon(), lwgeom_release(), lwline_as_lwgeom(), lwline_construct(), lwline_construct_empty(), PG_FUNCTION_INFO_V1(), LWTRIANGLE::points, POLYGONTYPE, LWPOLY::rings, LWCURVEPOLY::rings, LWGEOM::srid, LWTRIANGLE::srid, LWPOLY::srid, TRIANGLETYPE, and ovdump::type.

Referenced by LWGEOM_dimension().

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
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
POINTARRAY * points
Definition: liblwgeom.h:435
LWLINE * lwline_construct_empty(int srid, char hasz, char hasm)
Definition: lwline.c:64
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
LWGEOM ** rings
Definition: liblwgeom.h:537
#define POLYGONTYPE
Definition: liblwgeom.h:86
#define CURVEPOLYTYPE
Definition: liblwgeom.h:93
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
LWCURVEPOLY * lwgeom_as_lwcurvepoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:197
#define TRIANGLETYPE
Definition: liblwgeom.h:97
GBOX * bbox
Definition: liblwgeom.h:433
GBOX * bbox
Definition: liblwgeom.h:455
LWPOLY * lwgeom_as_lwpoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:206
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:930
int32_t srid
Definition: liblwgeom.h:401
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition: lwgeom.c:330
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:42
POINTARRAY ** rings
Definition: liblwgeom.h:459
LWTRIANGLE * lwgeom_as_lwtriangle(const LWGEOM *lwgeom)
Definition: lwgeom.c:215
int32_t srid
Definition: liblwgeom.h:456
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
void lwgeom_release(LWGEOM *lwgeom)
Free the containing LWGEOM and the associated BOX.
Definition: lwgeom.c:459
type
Definition: ovdump.py:41
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
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition: lwgeom.c:937
int32_t srid
Definition: liblwgeom.h:434
Here is the call graph for this function:
Here is the caller graph for this function: