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

Definition at line 717 of file lwgeom_ogc.c.

References CIRCSTRINGTYPE, geometry_serialize(), LINETYPE, lwgeom_free(), lwgeom_from_gserialized(), lwline_get_lwpoint(), lwpoint_as_lwgeom(), POINTARRAY::npoints, LWLINE::points, and LWGEOM::type.

718 {
719  GSERIALIZED *geom = (GSERIALIZED*)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
720  LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
721  LWPOINT *lwpoint = NULL;
722  int type = lwgeom->type;
723 
724  if ( type == LINETYPE || type == CIRCSTRINGTYPE )
725  {
726  LWLINE *line = (LWLINE*)lwgeom;
727  if ( line->points )
728  lwpoint = lwline_get_lwpoint((LWLINE*)lwgeom, line->points->npoints - 1);
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 }
#define LINETYPE
Definition: liblwgeom.h:61
LWPOINT * lwline_get_lwpoint(LWLINE *line, int where)
Returns freshly allocated LWPOINT that corresponds to the index where.
Definition: lwline.c:294
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int npoints
Definition: liblwgeom.h:327
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1006
LWGEOM * geom
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
uint8_t type
Definition: liblwgeom.h:352
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:254
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:67
POINTARRAY * points
Definition: liblwgeom.h:378

Here is the call graph for this function: