PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ LWGEOM_exteriorring_polygon()

Datum LWGEOM_exteriorring_polygon ( PG_FUNCTION_ARGS  )

Definition at line 474 of file lwgeom_ogc.c.

475 {
476  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
478  POINTARRAY *extring;
479  LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
480  LWLINE *line;
481  GBOX *bbox=NULL;
482 
483  if ( ! lwgeom_has_rings(lwgeom) )
484  PG_RETURN_NULL();
485 
486  if( lwgeom_is_empty(lwgeom) )
487  {
488  line = lwline_construct_empty(lwgeom->srid,
489  lwgeom_has_z(lwgeom),
490  lwgeom_has_m(lwgeom));
491  result = geometry_serialize(lwline_as_lwgeom(line));
492  }
493  else if ( lwgeom->type == POLYGONTYPE )
494  {
495  LWPOLY *poly = lwgeom_as_lwpoly(lwgeom);
496 
497  /* Ok, now we have a polygon. Here is its exterior ring. */
498  extring = poly->rings[0];
499 
500  /*
501  * This is a LWLINE constructed by exterior ring POINTARRAY
502  * If the input geom has a bbox, use it for
503  * the output geom, as exterior ring makes it up !
504  */
505  if ( poly->bbox )
506  bbox = gbox_copy(poly->bbox);
507 
508  line = lwline_construct(poly->srid, bbox, extring);
509  result = geometry_serialize((LWGEOM *)line);
510 
511  lwgeom_release((LWGEOM *)line);
512  }
513  else if ( lwgeom->type == TRIANGLETYPE )
514  {
515  LWTRIANGLE *triangle = lwgeom_as_lwtriangle(lwgeom);
516 
517  /*
518  * This is a LWLINE constructed by exterior ring POINTARRAY
519  * If the input geom has a bbox, use it for
520  * the output geom, as exterior ring makes it up !
521  */
522  if ( triangle->bbox )
523  bbox = gbox_copy(triangle->bbox);
524  line = lwline_construct(triangle->srid, bbox, triangle->points);
525 
526  result = geometry_serialize((LWGEOM *)line);
527 
528  lwgeom_release((LWGEOM *)line);
529  }
530  else
531  {
532  LWCURVEPOLY *curvepoly = lwgeom_as_lwcurvepoly(lwgeom);
533  result = geometry_serialize(curvepoly->rings[0]);
534  }
535 
536  lwgeom_free(lwgeom);
537  PG_FREE_IF_COPY(geom, 0);
538  PG_RETURN_POINTER(result);
539 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:267
GBOX * gbox_copy(const GBOX *box)
Return a copy of the GBOX, based on dimensionality of flags.
Definition: gbox.c:438
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:268
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition: lwgeom.c:339
int lwgeom_has_rings(const LWGEOM *geom)
Is this a type that has rings enclosing an area, but is not a collection of areas?...
Definition: lwgeom.c:1146
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1218
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:199
LWGEOM ** rings
Definition: liblwgeom.h:603
uint8_t type
Definition: liblwgeom.h:462
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, gbox_copy(), lwgeom_as_lwcurvepoly(), lwgeom_as_lwpoly(), lwgeom_as_lwtriangle(), lwgeom_free(), lwgeom_from_gserialized(), lwgeom_has_m(), lwgeom_has_rings(), 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 LWGEOM::type.

Here is the call graph for this function: