PostGIS  2.5.0dev-r@@SVN_REVISION@@
Datum LWGEOM_endpoint_linestring ( PG_FUNCTION_ARGS  )

Definition at line 749 of file lwgeom_ogc.c.

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.

750 {
751  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
752  LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
753  LWPOINT *lwpoint = NULL;
754  int type = lwgeom->type;
755 
756  if ( type == LINETYPE || type == CIRCSTRINGTYPE )
757  {
758  LWLINE *line = (LWLINE*)lwgeom;
759  if ( line->points )
760  lwpoint = lwline_get_lwpoint((LWLINE*)lwgeom, line->points->npoints - 1);
761  }
762  else if ( type == COMPOUNDTYPE )
763  {
764  lwpoint = lwcompound_get_endpoint((LWCOMPOUND*)lwgeom);
765  }
766 
767  lwgeom_free(lwgeom);
768  PG_FREE_IF_COPY(geom, 0);
769 
770  if ( ! lwpoint )
771  PG_RETURN_NULL();
772 
773  PG_RETURN_POINTER(geometry_serialize(lwpoint_as_lwgeom(lwpoint)));
774 }
#define LINETYPE
Definition: liblwgeom.h:85
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1137
#define COMPOUNDTYPE
Definition: liblwgeom.h:92
LWPOINT * lwcompound_get_endpoint(const LWCOMPOUND *lwcmp)
Definition: lwcompound.c:254
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
uint8_t type
Definition: liblwgeom.h:395
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:334
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:91
LWPOINT * lwline_get_lwpoint(const LWLINE *line, uint32_t where)
Returns freshly allocated LWPOINT that corresponds to the index where.
Definition: lwline.c:318
POINTARRAY * points
Definition: liblwgeom.h:421
uint32_t npoints
Definition: liblwgeom.h:370

Here is the call graph for this function: