PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ LWGEOM_endpoint_linestring()

Datum LWGEOM_endpoint_linestring ( PG_FUNCTION_ARGS  )

Definition at line 713 of file lwgeom_ogc.c.

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

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: