PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ LWGEOM_pointn_linestring()

Datum LWGEOM_pointn_linestring ( PG_FUNCTION_ARGS  )

Definition at line 553 of file lwgeom_ogc.c.

554 {
555  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
556  int where = PG_GETARG_INT32(1);
557  LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
558  LWPOINT *lwpoint = NULL;
559  int type = lwgeom->type;
560 
561  /* If index is negative, count backward */
562  if( where < 1 )
563  {
564  int count = -1;
565  if ( type == LINETYPE || type == CIRCSTRINGTYPE || type == COMPOUNDTYPE )
566  count = lwgeom_count_vertices(lwgeom);
567  if(count >0)
568  {
569  /* only work if we found the total point number */
570  /* converting where to positive backward indexing, +1 because 1 indexing */
571  where = where + count + 1;
572  }
573  if (where < 1)
574  PG_RETURN_NULL();
575  }
576 
577  if ( type == LINETYPE || type == CIRCSTRINGTYPE )
578  {
579  /* OGC index starts at one, so we substract first. */
580  lwpoint = lwline_get_lwpoint((LWLINE*)lwgeom, where - 1);
581  }
582  else if ( type == COMPOUNDTYPE )
583  {
584  lwpoint = lwcompound_get_lwpoint((LWCOMPOUND*)lwgeom, where - 1);
585  }
586 
587  lwgeom_free(lwgeom);
588  PG_FREE_IF_COPY(geom, 0);
589 
590  if ( ! lwpoint )
591  PG_RETURN_NULL();
592 
593  PG_RETURN_POINTER(geometry_serialize(lwpoint_as_lwgeom(lwpoint)));
594 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:239
#define COMPOUNDTYPE
Definition: liblwgeom.h:124
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1138
LWPOINT * lwcompound_get_lwpoint(const LWCOMPOUND *lwcmp, uint32_t where)
Definition: lwcompound.c:213
#define LINETYPE
Definition: liblwgeom.h:117
uint32_t lwgeom_count_vertices(const LWGEOM *geom)
Count the total number of vertices in any LWGEOM.
Definition: lwgeom.c:1229
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:327
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:123
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:476

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: