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

Definition at line 532 of file lwgeom_ogc.c.

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

533 {
534  GSERIALIZED *geom = (GSERIALIZED*)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
535  int where = PG_GETARG_INT32(1);
536  LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
537  LWPOINT *lwpoint = NULL;
538  int type = lwgeom->type;
539 
540  /* Can't handle crazy index! */
541  if ( where < 1 )
542  PG_RETURN_NULL();
543 
544  if ( type == LINETYPE || type == CIRCSTRINGTYPE )
545  {
546  /* OGC index starts at one, so we substract first. */
547  lwpoint = lwline_get_lwpoint((LWLINE*)lwgeom, where - 1);
548  }
549 
550  lwgeom_free(lwgeom);
551  PG_FREE_IF_COPY(geom, 0);
552 
553  if ( ! lwpoint )
554  PG_RETURN_NULL();
555 
556  PG_RETURN_POINTER(geometry_serialize(lwpoint_as_lwgeom(lwpoint)));
557 }
#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.
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

Here is the call graph for this function: