PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ LWGEOM_endpoint_linestring()

Datum LWGEOM_endpoint_linestring ( PG_FUNCTION_ARGS  )

Definition at line 854 of file lwgeom_ogc.c.

855 {
856  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
857  LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
858  LWPOINT *lwpoint = NULL;
859  int type = lwgeom->type;
860 
861  if ( type == LINETYPE || type == CIRCSTRINGTYPE )
862  {
863  LWLINE *line = (LWLINE*)lwgeom;
864  if ( line->points )
865  lwpoint = lwline_get_lwpoint((LWLINE*)lwgeom, line->points->npoints - 1);
866  }
867  else if ( type == COMPOUNDTYPE )
868  {
869  lwpoint = lwcompound_get_endpoint((LWCOMPOUND*)lwgeom);
870  }
871 
872  lwgeom_free(lwgeom);
873  PG_FREE_IF_COPY(geom, 0);
874 
875  if ( ! lwpoint )
876  PG_RETURN_NULL();
877 
878  PG_RETURN_POINTER(geometry_serialize(lwpoint_as_lwgeom(lwpoint)));
879 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:268
#define COMPOUNDTYPE
Definition: liblwgeom.h:110
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1218
#define LINETYPE
Definition: liblwgeom.h:103
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:344
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:109
LWPOINT * lwcompound_get_endpoint(const LWCOMPOUND *lwcmp)
Definition: lwcompound.c:297
LWPOINT * lwline_get_lwpoint(const LWLINE *line, uint32_t where)
Returns freshly allocated LWPOINT that corresponds to the index where.
Definition: lwline.c:309
type
Definition: ovdump.py:42
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, LWGEOM::type, and ovdump::type.

Here is the call graph for this function: