PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ LWGEOM_exteriorring_polygon()

Datum LWGEOM_exteriorring_polygon ( PG_FUNCTION_ARGS  )

Definition at line 468 of file lwgeom_ogc.c.

469{
470 GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
472 POINTARRAY *extring;
473 LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
474 LWLINE *line;
475 GBOX *bbox=NULL;
476
477 if ( ! lwgeom_has_rings(lwgeom) )
478 PG_RETURN_NULL();
479
480 if( lwgeom_is_empty(lwgeom) )
481 {
482 line = lwline_construct_empty(lwgeom->srid,
483 lwgeom_has_z(lwgeom),
484 lwgeom_has_m(lwgeom));
485 result = geometry_serialize(lwline_as_lwgeom(line));
486 }
487 else if ( lwgeom->type == POLYGONTYPE )
488 {
489 LWPOLY *poly = lwgeom_as_lwpoly(lwgeom);
490
491 /* Ok, now we have a polygon. Here is its exterior ring. */
492 extring = poly->rings[0];
493
494 /*
495 * This is a LWLINE constructed by exterior ring POINTARRAY
496 * If the input geom has a bbox, use it for
497 * the output geom, as exterior ring makes it up !
498 */
499 if ( poly->bbox )
500 bbox = gbox_copy(poly->bbox);
501
502 line = lwline_construct(poly->srid, bbox, extring);
503 result = geometry_serialize((LWGEOM *)line);
504
505 lwgeom_release((LWGEOM *)line);
506 }
507 else if ( lwgeom->type == TRIANGLETYPE )
508 {
509 LWTRIANGLE *triangle = lwgeom_as_lwtriangle(lwgeom);
510
511 /*
512 * This is a LWLINE constructed by exterior ring POINTARRAY
513 * If the input geom has a bbox, use it for
514 * the output geom, as exterior ring makes it up !
515 */
516 if ( triangle->bbox )
517 bbox = gbox_copy(triangle->bbox);
518 line = lwline_construct(triangle->srid, bbox, triangle->points);
519
520 result = geometry_serialize((LWGEOM *)line);
521
522 lwgeom_release((LWGEOM *)line);
523 }
524 else
525 {
526 LWCURVEPOLY *curvepoly = lwgeom_as_lwcurvepoly(lwgeom);
527 result = geometry_serialize(curvepoly->rings[0]);
528 }
529
530 lwgeom_free(lwgeom);
531 PG_FREE_IF_COPY(geom, 0);
532 PG_RETURN_POINTER(result);
533}
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.
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:1174
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1246
LWCURVEPOLY * lwgeom_as_lwcurvepoly(const LWGEOM *lwgeom)
Definition lwgeom.c:234
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition lwgeom.c:962
LWPOLY * lwgeom_as_lwpoly(const LWGEOM *lwgeom)
Definition lwgeom.c:243
LWLINE * lwline_construct(int32_t srid, GBOX *bbox, POINTARRAY *points)
Definition lwline.c:42
LWTRIANGLE * lwgeom_as_lwtriangle(const LWGEOM *lwgeom)
Definition lwgeom.c:252
#define POLYGONTYPE
Definition liblwgeom.h:104
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition lwgeom.c:367
#define TRIANGLETYPE
Definition liblwgeom.h:115
void lwgeom_release(LWGEOM *lwgeom)
Free the containing LWGEOM and the associated BOX.
Definition lwgeom.c:496
LWLINE * lwline_construct_empty(int32_t srid, char hasz, char hasm)
Definition lwline.c:55
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition lwgeom.c:969
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: