PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ LWGEOM_pointn_linestring()

Datum LWGEOM_pointn_linestring ( PG_FUNCTION_ARGS  )

Definition at line 691 of file lwgeom_ogc.c.

692{
693 GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
694 int where = PG_GETARG_INT32(1);
695 LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
696 LWPOINT *lwpoint = NULL;
697 int type = lwgeom->type;
698
699 /* If index is negative, count backward */
700 if( where < 1 )
701 {
702 int count = -1;
703 if ( type == LINETYPE || type == CIRCSTRINGTYPE || type == COMPOUNDTYPE )
705 if(count >0)
706 {
707 /* only work if we found the total point number */
708 /* converting where to positive backward indexing, +1 because 1 indexing */
709 where = where + count + 1;
710 }
711 if (where < 1)
712 PG_RETURN_NULL();
713 }
714
715 if ( type == LINETYPE || type == CIRCSTRINGTYPE )
716 {
717 /* OGC index starts at one, so we subtract first. */
718 lwpoint = lwline_get_lwpoint((LWLINE*)lwgeom, where - 1);
719 }
720 else if ( type == COMPOUNDTYPE )
721 {
722 lwpoint = lwcompound_get_lwpoint((LWCOMPOUND*)lwgeom, where - 1);
723 }
724
725 lwgeom_free(lwgeom);
726 PG_FREE_IF_COPY(geom, 0);
727
728 if ( ! lwpoint )
729 PG_RETURN_NULL();
730
731 PG_RETURN_POINTER(geometry_serialize(lwpoint_as_lwgeom(lwpoint)));
732}
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition lwgeom.c:372
#define COMPOUNDTYPE
Definition liblwgeom.h:110
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1246
LWPOINT * lwline_get_lwpoint(const LWLINE *line, uint32_t where)
Returns freshly allocated LWPOINT that corresponds to the index where.
Definition lwline.c:319
#define LINETYPE
Definition liblwgeom.h:103
LWPOINT * lwcompound_get_lwpoint(const LWCOMPOUND *lwcmp, uint32_t where)
Definition lwcompound.c:241
uint32_t lwgeom_count_vertices(const LWGEOM *geom)
Count the total number of vertices in any LWGEOM.
Definition lwgeom.c:1337
#define CIRCSTRINGTYPE
Definition liblwgeom.h:109
int count
Definition genraster.py:57
uint8_t type
Definition liblwgeom.h:462

References CIRCSTRINGTYPE, COMPOUNDTYPE, LINETYPE, lwcompound_get_lwpoint(), lwgeom_count_vertices(), lwgeom_free(), lwgeom_from_gserialized(), lwline_get_lwpoint(), lwpoint_as_lwgeom(), and LWGEOM::type.

Here is the call graph for this function: