PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ LWGEOM_exteriorring_polygon()

Datum LWGEOM_exteriorring_polygon ( PG_FUNCTION_ARGS  )

Definition at line 342 of file lwgeom_ogc.c.

343 {
344  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
346  POINTARRAY *extring;
347  LWGEOM *lwgeom;
348  LWLINE *line;
349  GBOX *bbox=NULL;
350  int type = gserialized_get_type(geom);
351 
352  POSTGIS_DEBUG(2, "LWGEOM_exteriorring_polygon called.");
353 
354  if ( (type != POLYGONTYPE) &&
355  (type != CURVEPOLYTYPE) &&
356  (type != TRIANGLETYPE))
357  {
358  PG_RETURN_NULL();
359  }
360 
361  lwgeom = lwgeom_from_gserialized(geom);
362 
363  if( lwgeom_is_empty(lwgeom) )
364  {
365  line = lwline_construct_empty(lwgeom->srid,
366  lwgeom_has_z(lwgeom),
367  lwgeom_has_m(lwgeom));
368  result = geometry_serialize(lwline_as_lwgeom(line));
369  }
370  else if ( type == POLYGONTYPE )
371  {
372  LWPOLY *poly = lwgeom_as_lwpoly(lwgeom);
373 
374  /* Ok, now we have a polygon. Here is its exterior ring. */
375  extring = poly->rings[0];
376 
377  /*
378  * This is a LWLINE constructed by exterior ring POINTARRAY
379  * If the input geom has a bbox, use it for
380  * the output geom, as exterior ring makes it up !
381  */
382  if ( poly->bbox )
383  bbox = gbox_copy(poly->bbox);
384 
385  line = lwline_construct(poly->srid, bbox, extring);
386  result = geometry_serialize((LWGEOM *)line);
387 
388  lwgeom_release((LWGEOM *)line);
389  }
390  else if ( type == TRIANGLETYPE )
391  {
392  LWTRIANGLE *triangle = lwgeom_as_lwtriangle(lwgeom);
393 
394  /*
395  * This is a LWLINE constructed by exterior ring POINTARRAY
396  * If the input geom has a bbox, use it for
397  * the output geom, as exterior ring makes it up !
398  */
399  if ( triangle->bbox )
400  bbox = gbox_copy(triangle->bbox);
401  line = lwline_construct(triangle->srid, bbox, triangle->points);
402 
403  result = geometry_serialize((LWGEOM *)line);
404 
405  lwgeom_release((LWGEOM *)line);
406  }
407  else
408  {
409  LWCURVEPOLY *curvepoly = lwgeom_as_lwcurvepoly(lwgeom);
410  result = geometry_serialize(curvepoly->rings[0]);
411  }
412 
413  lwgeom_free(lwgeom);
414  PG_FREE_IF_COPY(geom, 0);
415  PG_RETURN_POINTER(result);
416 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:262
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:339
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1155
#define CURVEPOLYTYPE
Definition: liblwgeom.h:111
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:934
LWLINE * lwline_construct(int32_t srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:42
LWTRIANGLE * lwgeom_as_lwtriangle(const LWGEOM *lwgeom)
Definition: lwgeom.c:224
#define POLYGONTYPE
Definition: liblwgeom.h:104
LWCURVEPOLY * lwgeom_as_lwcurvepoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:206
#define TRIANGLETYPE
Definition: liblwgeom.h:115
LWPOLY * lwgeom_as_lwpoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:215
void lwgeom_release(LWGEOM *lwgeom)
Free the containing LWGEOM and the associated BOX.
Definition: lwgeom.c:468
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition: lwgeom.c:941
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:203
type
Definition: ovdump.py:42
LWGEOM ** rings
Definition: liblwgeom.h:603
int32_t srid
Definition: liblwgeom.h:460
POINTARRAY ** rings
Definition: liblwgeom.h:519
GBOX * bbox
Definition: liblwgeom.h:518
int32_t srid
Definition: liblwgeom.h:520
int32_t srid
Definition: liblwgeom.h:496
GBOX * bbox
Definition: liblwgeom.h:494
POINTARRAY * points
Definition: liblwgeom.h:495

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

Here is the call graph for this function: