PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ LWGEOM_pointn_linestring()

Datum LWGEOM_pointn_linestring ( PG_FUNCTION_ARGS  )

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

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