PostGIS  2.3.7dev-r@@SVN_REVISION@@
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_release(), lwline_as_lwgeom(), lwline_construct(), lwline_construct_empty(), LWTRIANGLE::points, POLYGONTYPE, LWPOLY::rings, LWCURVEPOLY::rings, LWGEOM::srid, LWTRIANGLE::srid, LWPOLY::srid, TRIANGLETYPE, and LWGEOM::type.

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  elog(ERROR, "ExteriorRing: geom is not a polygon");
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 ( lwgeom->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 ( lwgeom->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: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:69
POINTARRAY * points
Definition: liblwgeom.h:432
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:534
#define POLYGONTYPE
Definition: liblwgeom.h:86
#define CURVEPOLYTYPE
Definition: liblwgeom.h:93
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1063
LWCURVEPOLY * lwgeom_as_lwcurvepoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:129
#define TRIANGLETYPE
Definition: liblwgeom.h:97
GBOX * bbox
Definition: liblwgeom.h:430
GBOX * bbox
Definition: liblwgeom.h:452
LWPOLY * lwgeom_as_lwpoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:138
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:849
int32_t srid
Definition: liblwgeom.h:398
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition: lwgeom.c:262
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:42
POINTARRAY ** rings
Definition: liblwgeom.h:456
LWTRIANGLE * lwgeom_as_lwtriangle(const LWGEOM *lwgeom)
Definition: lwgeom.c:147
int32_t srid
Definition: liblwgeom.h:453
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
void lwgeom_release(LWGEOM *lwgeom)
Free the containing LWGEOM and the associated BOX.
Definition: lwgeom.c:385
uint8_t type
Definition: liblwgeom.h:395
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:1310
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition: lwgeom.c:856
int32_t srid
Definition: liblwgeom.h:431

Here is the call graph for this function: