PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ LWGEOM_pointn_linestring()

Datum LWGEOM_pointn_linestring ( PG_FUNCTION_ARGS  )

Definition at line 527 of file lwgeom_ogc.c.

References CIRCSTRINGTYPE, COMPOUNDTYPE, geometry_serialize(), LINETYPE, lwcompound_get_lwpoint(), lwgeom_free(), lwgeom_from_gserialized(), LWGEOM_x_point(), lwline_get_lwpoint(), lwpoint_as_lwgeom(), PG_FUNCTION_INFO_V1(), ovdump::type, and LWGEOM::type.

Referenced by LWGEOM_interiorringn_polygon().

528 {
529  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
530  int where = PG_GETARG_INT32(1);
531  LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
532  LWPOINT *lwpoint = NULL;
533  int type = lwgeom->type;
534 
535  /* Can't handle crazy index! */
536  if ( where < 1 )
537  PG_RETURN_NULL();
538 
539  if ( type == LINETYPE || type == CIRCSTRINGTYPE )
540  {
541  /* OGC index starts at one, so we substract first. */
542  lwpoint = lwline_get_lwpoint((LWLINE*)lwgeom, where - 1);
543  }
544  else if ( type == COMPOUNDTYPE )
545  {
546  lwpoint = lwcompound_get_lwpoint((LWCOMPOUND*)lwgeom, where - 1);
547  }
548 
549  lwgeom_free(lwgeom);
550  PG_FREE_IF_COPY(geom, 0);
551 
552  if ( ! lwpoint )
553  PG_RETURN_NULL();
554 
555  PG_RETURN_POINTER(geometry_serialize(lwpoint_as_lwgeom(lwpoint)));
556 }
#define LINETYPE
Definition: liblwgeom.h:71
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1050
#define COMPOUNDTYPE
Definition: liblwgeom.h:78
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
LWPOINT * lwcompound_get_lwpoint(const LWCOMPOUND *lwcmp, int where)
Definition: lwcompound.c:200
Here is the call graph for this function:
Here is the caller graph for this function: