510{
512 double from = PG_GETARG_FLOAT8(1);
513 double to = PG_GETARG_FLOAT8(2);
518
519 if ( from < 0 || from > 1 )
520 {
521 elog(ERROR,"line_interpolate_point: 2nd arg isn't within [0,1]");
522 PG_RETURN_NULL();
523 }
524
525 if ( to < 0 || to > 1 )
526 {
527 elog(ERROR,"line_interpolate_point: 3rd arg isn't within [0,1]");
528 PG_RETURN_NULL();
529 }
530
531 if ( from > to )
532 {
533 elog(ERROR, "2nd arg must be smaller then 3rd arg");
534 PG_RETURN_NULL();
535 }
536
538 {
540
542 {
543
545 PG_FREE_IF_COPY(geom, 0);
546 PG_RETURN_NULL();
547 }
548
549 ipa = iline->points;
550
552
555 else
557
558 }
560 {
562 uint32_t i = 0, g = 0;
565 double length = 0.0, sublength = 0.0, minprop = 0.0, maxprop = 0.0;
566
568
570 {
571
573 PG_FREE_IF_COPY(geom, 0);
574 PG_RETURN_NULL();
575 }
576
577
578 for ( i = 0; i < iline->ngeoms; i++ )
579 {
581 if ( subline->points && subline->points->npoints > 1 )
583 }
584
586
587
588 for ( i = 0; i < iline->ngeoms; i++ )
589 {
591 double subfrom = 0.0, subto = 0.0;
592
593 if ( subline->points && subline->points->npoints > 1 )
595
596
597 minprop = maxprop;
598 maxprop = sublength / length;
599
600
601
602 if ( from > maxprop || to < minprop )
603 continue;
604
605 if ( from <= minprop )
606 subfrom = 0.0;
607 if ( to >= maxprop )
608 subto = 1.0;
609
610 if ( from > minprop && from <= maxprop )
611 subfrom = (from - minprop) / (maxprop - minprop);
612
613 if ( to < maxprop && to >= minprop )
614 subto = (to - minprop) / (maxprop - minprop);
615
616
619 {
621 {
624 }
625 else
626 {
628 }
629 g++;
630 }
631
632
633
634 }
635
636 if ( ! homogeneous )
638
640 }
641 else
642 {
643 elog(ERROR,"line_substring: 1st arg isn't a line");
644 PG_RETURN_NULL();
645 }
646
647 ret = geometry_serialize(olwgeom);
649 PG_FREE_IF_COPY(geom, 0);
650 PG_RETURN_POINTER(ret);
651
652}
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
uint32_t gserialized_get_type(const GSERIALIZED *g)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
LWCOLLECTION * lwcollection_construct(uint8_t type, int32_t srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
void lwgeom_free(LWGEOM *geom)
POINTARRAY * ptarray_substring(POINTARRAY *pa, double d1, double d2, double tolerance)
@d1 start location (distance from start / total distance) @d2 end location (distance from start / tot...
LWPOINT * lwpoint_construct(int32_t srid, GBOX *bbox, POINTARRAY *point)
void lwline_release(LWLINE *lwline)
double ptarray_length_2d(const POINTARRAY *pts)
Find the 2d length of the given POINTARRAY (even if it's 3d)
void lwmline_release(LWMLINE *lwline)
void * lwalloc(size_t size)
LWLINE * lwline_construct(int32_t srid, GBOX *bbox, POINTARRAY *points)
LWMLINE * lwgeom_as_lwmline(const LWGEOM *lwgeom)
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
#define LW_TRUE
Return types for functions with status returns.
#define SRID_UNKNOWN
Unknown SRID value.
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)