PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ LWGEOM_pointn_linestring()

Datum LWGEOM_pointn_linestring ( PG_FUNCTION_ARGS  )

Definition at line 544 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().

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