PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ LWGEOM_endpoint_linestring()

Datum LWGEOM_endpoint_linestring ( PG_FUNCTION_ARGS  )

Definition at line 720 of file lwgeom_ogc.c.

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

Referenced by LWGEOM_startpoint_linestring().

721 {
722  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
723  LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
724  LWPOINT *lwpoint = NULL;
725  int type = lwgeom->type;
726 
727  if ( type == LINETYPE || type == CIRCSTRINGTYPE )
728  {
729  LWLINE *line = (LWLINE*)lwgeom;
730  if ( line->points )
731  lwpoint = lwline_get_lwpoint((LWLINE*)lwgeom, line->points->npoints - 1);
732  }
733  else if ( type == COMPOUNDTYPE )
734  {
735  lwpoint = lwcompound_get_endpoint((LWCOMPOUND*)lwgeom);
736  }
737 
738  lwgeom_free(lwgeom);
739  PG_FREE_IF_COPY(geom, 0);
740 
741  if ( ! lwpoint )
742  PG_RETURN_NULL();
743 
744  PG_RETURN_POINTER(geometry_serialize(lwpoint_as_lwgeom(lwpoint)));
745 }
#define LINETYPE
Definition: liblwgeom.h:71
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int npoints
Definition: liblwgeom.h:355
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1050
#define COMPOUNDTYPE
Definition: liblwgeom.h:78
LWPOINT * lwcompound_get_endpoint(const LWCOMPOUND *lwcmp)
Definition: lwcompound.c:241
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
LWPOINT * lwline_get_lwpoint(const LWLINE *line, int where)
Returns freshly allocated LWPOINT that corresponds to the index where.
Definition: lwline.c:295
uint8_t type
Definition: liblwgeom.h:380
type
Definition: ovdump.py:41
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:254
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:77
POINTARRAY * points
Definition: liblwgeom.h:406
Here is the call graph for this function:
Here is the caller graph for this function: