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

◆ LWGEOM_endpoint_linestring()

Datum LWGEOM_endpoint_linestring ( PG_FUNCTION_ARGS  )

Definition at line 712 of file lwgeom_ogc.c.

713{
714 GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
715 LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
716 LWPOINT *lwpoint = NULL;
717 int type = lwgeom->type;
718
719 if ( type == LINETYPE || type == CIRCSTRINGTYPE )
720 {
721 LWLINE *line = (LWLINE*)lwgeom;
722 if ( line->points )
723 lwpoint = lwline_get_lwpoint((LWLINE*)lwgeom, line->points->npoints - 1);
724 }
725 else if ( type == COMPOUNDTYPE )
726 {
727 lwpoint = lwcompound_get_endpoint((LWCOMPOUND*)lwgeom);
728 }
729
730 lwgeom_free(lwgeom);
731 PG_FREE_IF_COPY(geom, 0);
732
733 if ( ! lwpoint )
734 PG_RETURN_NULL();
735
736 PG_RETURN_POINTER(geometry_serialize(lwpoint_as_lwgeom(lwpoint)));
737}
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition lwgeom.c:326
#define COMPOUNDTYPE
Definition liblwgeom.h:124
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1138
LWPOINT * lwline_get_lwpoint(const LWLINE *line, uint32_t where)
Returns freshly allocated LWPOINT that corresponds to the index where.
Definition lwline.c:309
#define LINETYPE
Definition liblwgeom.h:117
LWPOINT * lwcompound_get_endpoint(const LWCOMPOUND *lwcmp)
Definition lwcompound.c:254
#define CIRCSTRINGTYPE
Definition liblwgeom.h:123
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
uint8_t type
Definition liblwgeom.h:448
POINTARRAY * points
Definition liblwgeom.h:469
uint32_t npoints
Definition liblwgeom.h:413

References CIRCSTRINGTYPE, COMPOUNDTYPE, geometry_serialize(), LINETYPE, lwcompound_get_endpoint(), lwgeom_free(), lwgeom_from_gserialized(), lwline_get_lwpoint(), lwpoint_as_lwgeom(), POINTARRAY::npoints, LWLINE::points, and LWGEOM::type.

Here is the call graph for this function: