PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ LWGEOM_pointn_linestring()

Datum LWGEOM_pointn_linestring ( PG_FUNCTION_ARGS  )

Definition at line 697 of file lwgeom_ogc.c.

698 {
699  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
700  int where = PG_GETARG_INT32(1);
701  LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
702  LWPOINT *lwpoint = NULL;
703  int type = lwgeom->type;
704 
705  /* If index is negative, count backward */
706  if( where < 1 )
707  {
708  int count = -1;
709  if ( type == LINETYPE || type == CIRCSTRINGTYPE || type == COMPOUNDTYPE )
710  count = lwgeom_count_vertices(lwgeom);
711  if(count >0)
712  {
713  /* only work if we found the total point number */
714  /* converting where to positive backward indexing, +1 because 1 indexing */
715  where = where + count + 1;
716  }
717  if (where < 1)
718  PG_RETURN_NULL();
719  }
720 
721  if ( type == LINETYPE || type == CIRCSTRINGTYPE )
722  {
723  /* OGC index starts at one, so we subtract first. */
724  lwpoint = lwline_get_lwpoint((LWLINE*)lwgeom, where - 1);
725  }
726  else if ( type == COMPOUNDTYPE )
727  {
728  lwpoint = lwcompound_get_lwpoint((LWCOMPOUND*)lwgeom, where - 1);
729  }
730 
731  lwgeom_free(lwgeom);
732  PG_FREE_IF_COPY(geom, 0);
733 
734  if ( ! lwpoint )
735  PG_RETURN_NULL();
736 
737  PG_RETURN_POINTER(geometry_serialize(lwpoint_as_lwgeom(lwpoint)));
738 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:268
#define COMPOUNDTYPE
Definition: liblwgeom.h:110
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1218
LWPOINT * lwcompound_get_lwpoint(const LWCOMPOUND *lwcmp, uint32_t where)
Definition: lwcompound.c:256
#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:1309
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: