PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ LWGEOM_pointn_linestring()

Datum LWGEOM_pointn_linestring ( PG_FUNCTION_ARGS  )

Definition at line 545 of file lwgeom_ogc.c.

546 {
547  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
548  int where = PG_GETARG_INT32(1);
549  LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
550  LWPOINT *lwpoint = NULL;
551  int type = lwgeom->type;
552 
553  /* If index is negative, count backward */
554  if( where < 1 )
555  {
556  int count = -1;
557  if ( type == LINETYPE || type == CIRCSTRINGTYPE || type == COMPOUNDTYPE )
558  count = lwgeom_count_vertices(lwgeom);
559  if(count >0)
560  {
561  /* only work if we found the total point number */
562  /* converting where to positive backward indexing, +1 because 1 indexing */
563  where = where + count + 1;
564  }
565  if (where < 1)
566  PG_RETURN_NULL();
567  }
568 
569  if ( type == LINETYPE || type == CIRCSTRINGTYPE )
570  {
571  /* OGC index starts at one, so we substract first. */
572  lwpoint = lwline_get_lwpoint((LWLINE*)lwgeom, where - 1);
573  }
574  else if ( type == COMPOUNDTYPE )
575  {
576  lwpoint = lwcompound_get_lwpoint((LWCOMPOUND*)lwgeom, where - 1);
577  }
578 
579  lwgeom_free(lwgeom);
580  PG_FREE_IF_COPY(geom, 0);
581 
582  if ( ! lwpoint )
583  PG_RETURN_NULL();
584 
585  PG_RETURN_POINTER(geometry_serialize(lwpoint_as_lwgeom(lwpoint)));
586 }
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
LWPOINT * lwcompound_get_lwpoint(const LWCOMPOUND *lwcmp, uint32_t where)
Definition: lwcompound.c:213
#define LINETYPE
Definition: liblwgeom.h:86
uint32_t lwgeom_count_vertices(const LWGEOM *geom)
Count the total number of vertices in any LWGEOM.
Definition: lwgeom.c:1235
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:335
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:92
LWPOINT * lwline_get_lwpoint(const LWLINE *line, uint32_t where)
Returns freshly allocated LWPOINT that corresponds to the index where.
Definition: lwline.c:318
int count
Definition: genraster.py:56
type
Definition: ovdump.py:41
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
uint8_t type
Definition: liblwgeom.h:399

References CIRCSTRINGTYPE, COMPOUNDTYPE, genraster::count, geometry_serialize(), LINETYPE, lwcompound_get_lwpoint(), lwgeom_count_vertices(), lwgeom_free(), lwgeom_from_gserialized(), lwline_get_lwpoint(), lwpoint_as_lwgeom(), LWGEOM::type, and ovdump::type.

Here is the call graph for this function: