PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ LWGEOM_endpoint_linestring()

Datum LWGEOM_endpoint_linestring ( PG_FUNCTION_ARGS  )

Definition at line 750 of file lwgeom_ogc.c.

751 {
752  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
753  LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
754  LWPOINT *lwpoint = NULL;
755  int type = lwgeom->type;
756 
757  if ( type == LINETYPE || type == CIRCSTRINGTYPE )
758  {
759  LWLINE *line = (LWLINE*)lwgeom;
760  if ( line->points )
761  lwpoint = lwline_get_lwpoint((LWLINE*)lwgeom, line->points->npoints - 1);
762  }
763  else if ( type == COMPOUNDTYPE )
764  {
765  lwpoint = lwcompound_get_endpoint((LWCOMPOUND*)lwgeom);
766  }
767 
768  lwgeom_free(lwgeom);
769  PG_FREE_IF_COPY(geom, 0);
770 
771  if ( ! lwpoint )
772  PG_RETURN_NULL();
773 
774  PG_RETURN_POINTER(geometry_serialize(lwpoint_as_lwgeom(lwpoint)));
775 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
#define COMPOUNDTYPE
Definition: liblwgeom.h:93
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
#define LINETYPE
Definition: liblwgeom.h:86
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:335
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:92
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:318
type
Definition: ovdump.py:41
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
uint8_t type
Definition: liblwgeom.h:399
POINTARRAY * points
Definition: liblwgeom.h:425
uint32_t npoints
Definition: liblwgeom.h:374

References CIRCSTRINGTYPE, COMPOUNDTYPE, geometry_serialize(), 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: