PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ LWGEOM_exteriorring_polygon()

Datum LWGEOM_exteriorring_polygon ( PG_FUNCTION_ARGS  )

Definition at line 328 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().

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