PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ LWGEOM_pointn_linestring()

Datum LWGEOM_pointn_linestring ( PG_FUNCTION_ARGS  )

Definition at line 558 of file lwgeom_ogc.c.

559 {
560  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
561  int where = PG_GETARG_INT32(1);
562  LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
563  LWPOINT *lwpoint = NULL;
564  int type = lwgeom->type;
565 
566  /* If index is negative, count backward */
567  if( where < 1 )
568  {
569  int count = -1;
570  if ( type == LINETYPE || type == CIRCSTRINGTYPE || type == COMPOUNDTYPE )
571  count = lwgeom_count_vertices(lwgeom);
572  if(count >0)
573  {
574  /* only work if we found the total point number */
575  /* converting where to positive backward indexing, +1 because 1 indexing */
576  where = where + count + 1;
577  }
578  if (where < 1)
579  PG_RETURN_NULL();
580  }
581 
582  if ( type == LINETYPE || type == CIRCSTRINGTYPE )
583  {
584  /* OGC index starts at one, so we substract first. */
585  lwpoint = lwline_get_lwpoint((LWLINE*)lwgeom, where - 1);
586  }
587  else if ( type == COMPOUNDTYPE )
588  {
589  lwpoint = lwcompound_get_lwpoint((LWCOMPOUND*)lwgeom, where - 1);
590  }
591 
592  lwgeom_free(lwgeom);
593  PG_FREE_IF_COPY(geom, 0);
594 
595  if ( ! lwpoint )
596  PG_RETURN_NULL();
597 
598  PG_RETURN_POINTER(geometry_serialize(lwpoint_as_lwgeom(lwpoint)));
599 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:239
#define COMPOUNDTYPE
Definition: liblwgeom.h:110
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1155
LWPOINT * lwcompound_get_lwpoint(const LWCOMPOUND *lwcmp, uint32_t where)
Definition: lwcompound.c:213
#define LINETYPE
Definition: liblwgeom.h:103
uint32_t lwgeom_count_vertices(const LWGEOM *geom)
Count the total number of vertices in any LWGEOM.
Definition: lwgeom.c:1246
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:344
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:109
LWPOINT * lwline_get_lwpoint(const LWLINE *line, uint32_t where)
Returns freshly allocated LWPOINT that corresponds to the index where.
Definition: lwline.c:309
int count
Definition: genraster.py:57
type
Definition: ovdump.py:42
uint8_t type
Definition: liblwgeom.h:462

References CIRCSTRINGTYPE, COMPOUNDTYPE, genraster::count, 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: