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

◆ LWGEOM_pointn_linestring()

Datum LWGEOM_pointn_linestring ( PG_FUNCTION_ARGS  )

Definition at line 552 of file lwgeom_ogc.c.

553{
554 GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
555 int where = PG_GETARG_INT32(1);
556 LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
557 LWPOINT *lwpoint = NULL;
558 int type = lwgeom->type;
559
560 /* If index is negative, count backward */
561 if( where < 1 )
562 {
563 int count = -1;
564 if ( type == LINETYPE || type == CIRCSTRINGTYPE || type == COMPOUNDTYPE )
566 if(count >0)
567 {
568 /* only work if we found the total point number */
569 /* converting where to positive backward indexing, +1 because 1 indexing */
570 where = where + count + 1;
571 }
572 if (where < 1)
573 PG_RETURN_NULL();
574 }
575
576 if ( type == LINETYPE || type == CIRCSTRINGTYPE )
577 {
578 /* OGC index starts at one, so we substract first. */
579 lwpoint = lwline_get_lwpoint((LWLINE*)lwgeom, where - 1);
580 }
581 else if ( type == COMPOUNDTYPE )
582 {
583 lwpoint = lwcompound_get_lwpoint((LWCOMPOUND*)lwgeom, where - 1);
584 }
585
586 lwgeom_free(lwgeom);
587 PG_FREE_IF_COPY(geom, 0);
588
589 if ( ! lwpoint )
590 PG_RETURN_NULL();
591
592 PG_RETURN_POINTER(geometry_serialize(lwpoint_as_lwgeom(lwpoint)));
593}
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition lwgeom.c:326
#define COMPOUNDTYPE
Definition liblwgeom.h:124
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1138
LWPOINT * lwline_get_lwpoint(const LWLINE *line, uint32_t where)
Returns freshly allocated LWPOINT that corresponds to the index where.
Definition lwline.c:309
#define LINETYPE
Definition liblwgeom.h:117
LWPOINT * lwcompound_get_lwpoint(const LWCOMPOUND *lwcmp, uint32_t where)
Definition lwcompound.c:213
uint32_t lwgeom_count_vertices(const LWGEOM *geom)
Count the total number of vertices in any LWGEOM.
Definition lwgeom.c:1229
#define CIRCSTRINGTYPE
Definition liblwgeom.h:123
int count
Definition genraster.py:57
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
uint8_t type
Definition liblwgeom.h:448

References CIRCSTRINGTYPE, COMPOUNDTYPE, geometry_serialize(), 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: