PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ LWGEOM_endpoint_linestring()

Datum LWGEOM_endpoint_linestring ( PG_FUNCTION_ARGS  )

Definition at line 715 of file lwgeom_ogc.c.

716 {
717  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
718  LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
719  LWPOINT *lwpoint = NULL;
720  int type = lwgeom->type;
721 
722  if ( type == LINETYPE || type == CIRCSTRINGTYPE )
723  {
724  LWLINE *line = (LWLINE*)lwgeom;
725  if ( line->points )
726  lwpoint = lwline_get_lwpoint((LWLINE*)lwgeom, line->points->npoints - 1);
727  }
728  else if ( type == COMPOUNDTYPE )
729  {
730  lwpoint = lwcompound_get_endpoint((LWCOMPOUND*)lwgeom);
731  }
732 
733  lwgeom_free(lwgeom);
734  PG_FREE_IF_COPY(geom, 0);
735 
736  if ( ! lwpoint )
737  PG_RETURN_NULL();
738 
739  PG_RETURN_POINTER(geometry_serialize(lwpoint_as_lwgeom(lwpoint)));
740 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:239
#define COMPOUNDTYPE
Definition: liblwgeom.h:110
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1155
#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:254
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: