PostGIS  2.3.7dev-r@@SVN_REVISION@@
Datum LWGEOM_startpoint_linestring ( PG_FUNCTION_ARGS  )

Definition at line 716 of file lwgeom_ogc.c.

References CIRCSTRINGTYPE, COMPOUNDTYPE, geometry_serialize(), LINETYPE, lwcompound_get_startpoint(), lwgeom_free(), lwgeom_from_gserialized(), lwline_get_lwpoint(), lwpoint_as_lwgeom(), and LWGEOM::type.

717 {
718  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
719  LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
720  LWPOINT *lwpoint = NULL;
721  int type = lwgeom->type;
722 
723  if ( type == LINETYPE || type == CIRCSTRINGTYPE )
724  {
725  lwpoint = lwline_get_lwpoint((LWLINE*)lwgeom, 0);
726  }
727  else if ( type == COMPOUNDTYPE )
728  {
729  lwpoint = lwcompound_get_startpoint((LWCOMPOUND*)lwgeom);
730  }
731 
732  lwgeom_free(lwgeom);
733  PG_FREE_IF_COPY(geom, 0);
734 
735  if ( ! lwpoint )
736  PG_RETURN_NULL();
737 
738  PG_RETURN_POINTER(geometry_serialize(lwpoint_as_lwgeom(lwpoint)));
739 }
#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:1063
#define COMPOUNDTYPE
Definition: liblwgeom.h:92
LWPOINT * lwcompound_get_startpoint(const LWCOMPOUND *lwcmp)
Definition: lwcompound.c:248
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:324
uint8_t type
Definition: liblwgeom.h:395
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:267
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:91

Here is the call graph for this function: