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

◆ LWGEOM_endpoint_linestring()

Datum LWGEOM_endpoint_linestring ( PG_FUNCTION_ARGS  )

Definition at line 848 of file lwgeom_ogc.c.

849{
850 GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
851 LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
852 LWPOINT *lwpoint = NULL;
853 int type = lwgeom->type;
854
855 if ( type == LINETYPE || type == CIRCSTRINGTYPE )
856 {
857 LWLINE *line = (LWLINE*)lwgeom;
858 if ( line->points )
859 lwpoint = lwline_get_lwpoint((LWLINE*)lwgeom, line->points->npoints - 1);
860 }
861 else if ( type == COMPOUNDTYPE )
862 {
863 lwpoint = lwcompound_get_endpoint((LWCOMPOUND*)lwgeom);
864 }
865
866 lwgeom_free(lwgeom);
867 PG_FREE_IF_COPY(geom, 0);
868
869 if ( ! lwpoint )
870 PG_RETURN_NULL();
871
872 PG_RETURN_POINTER(geometry_serialize(lwpoint_as_lwgeom(lwpoint)));
873}
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition lwgeom.c:372
#define COMPOUNDTYPE
Definition liblwgeom.h:110
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1246
LWPOINT * lwline_get_lwpoint(const LWLINE *line, uint32_t where)
Returns freshly allocated LWPOINT that corresponds to the index where.
Definition lwline.c:319
#define LINETYPE
Definition liblwgeom.h:103
LWPOINT * lwcompound_get_endpoint(const LWCOMPOUND *lwcmp)
Definition lwcompound.c:282
#define CIRCSTRINGTYPE
Definition liblwgeom.h:109
uint8_t type
Definition liblwgeom.h:462
POINTARRAY * points
Definition liblwgeom.h:483
uint32_t npoints
Definition liblwgeom.h:427

References CIRCSTRINGTYPE, COMPOUNDTYPE, 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: