PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ LWGEOM_pointn_linestring()

Datum LWGEOM_pointn_linestring ( PG_FUNCTION_ARGS  )

Definition at line 541 of file lwgeom_ogc.c.

References CIRCSTRINGTYPE, COMPOUNDTYPE, genraster::count, geometry_serialize(), LINETYPE, lwcompound_get_lwpoint(), lwgeom_count_vertices(), 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().

542 {
543  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
544  int where = PG_GETARG_INT32(1);
545  LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
546  LWPOINT *lwpoint = NULL;
547  int type = lwgeom->type;
548 
549  /* If index is negative, count backward */
550  if( where < 1 )
551  {
552  int count = -1;
553  if ( type == LINETYPE || type == CIRCSTRINGTYPE || type == COMPOUNDTYPE )
554  count = lwgeom_count_vertices(lwgeom);
555  if(count >0)
556  {
557  /* only work if we found the total point number */
558  /* converting where to positive backward indexing, +1 because 1 indexing */
559  where = where + count + 1;
560  }
561  if (where < 1)
562  PG_RETURN_NULL();
563  }
564 
565  if ( type == LINETYPE || type == CIRCSTRINGTYPE )
566  {
567  /* OGC index starts at one, so we substract first. */
568  lwpoint = lwline_get_lwpoint((LWLINE*)lwgeom, where - 1);
569  }
570  else if ( type == COMPOUNDTYPE )
571  {
572  lwpoint = lwcompound_get_lwpoint((LWCOMPOUND*)lwgeom, where - 1);
573  }
574 
575  lwgeom_free(lwgeom);
576  PG_FREE_IF_COPY(geom, 0);
577 
578  if ( ! lwpoint )
579  PG_RETURN_NULL();
580 
581  PG_RETURN_POINTER(geometry_serialize(lwpoint_as_lwgeom(lwpoint)));
582 }
#define LINETYPE
Definition: liblwgeom.h:85
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1063
#define COMPOUNDTYPE
Definition: liblwgeom.h:92
int count
Definition: genraster.py:56
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:324
uint8_t type
Definition: liblwgeom.h:395
type
Definition: ovdump.py:41
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:267
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:91
int lwgeom_count_vertices(const LWGEOM *geom)
Count the total number of vertices in any LWGEOM.
Definition: lwgeom.c:1153
LWPOINT * lwcompound_get_lwpoint(const LWCOMPOUND *lwcmp, int where)
Definition: lwcompound.c:213
Here is the call graph for this function:
Here is the caller graph for this function: