516{
518 double from = PG_GETARG_FLOAT8(1);
519 double to = PG_GETARG_FLOAT8(2);
524
525 if ( from < 0 || from > 1 )
526 {
527 elog(ERROR,"line_interpolate_point: 2nd arg isn't within [0,1]");
528 PG_RETURN_NULL();
529 }
530
531 if ( to < 0 || to > 1 )
532 {
533 elog(ERROR,"line_interpolate_point: 3rd arg isn't within [0,1]");
534 PG_RETURN_NULL();
535 }
536
537 if ( from > to )
538 {
539 elog(ERROR, "2nd arg must be smaller then 3rd arg");
540 PG_RETURN_NULL();
541 }
542
544 {
546
548 {
549
551 PG_FREE_IF_COPY(geom, 0);
552 PG_RETURN_NULL();
553 }
554
555 ipa = iline->points;
556
558
561 else
563
564 }
566 {
568 uint32_t i = 0, g = 0;
571 double length = 0.0, sublength = 0.0, minprop = 0.0, maxprop = 0.0;
572
574
576 {
577
579 PG_FREE_IF_COPY(geom, 0);
580 PG_RETURN_NULL();
581 }
582
583
584 for ( i = 0; i < iline->ngeoms; i++ )
585 {
587 if ( subline->points && subline->points->npoints > 1 )
589 }
590
592
593
594 for ( i = 0; i < iline->ngeoms; i++ )
595 {
597 double subfrom = 0.0, subto = 0.0;
598
599 if ( subline->points && subline->points->npoints > 1 )
601
602
603 minprop = maxprop;
604 maxprop = sublength / length;
605
606
607
608 if ( from > maxprop || to < minprop )
609 continue;
610
611 if ( from <= minprop )
612 subfrom = 0.0;
613 if ( to >= maxprop )
614 subto = 1.0;
615
616 if ( from > minprop && from <= maxprop )
617 subfrom = (from - minprop) / (maxprop - minprop);
618
619 if ( to < maxprop && to >= minprop )
620 subto = (to - minprop) / (maxprop - minprop);
621
622
625 {
627 {
630 }
631 else
632 {
634 }
635 g++;
636 }
637
638
639
640 }
641
642 if ( ! homogeneous )
644
646 }
647 else
648 {
649 elog(ERROR,"line_substring: 1st arg isn't a line");
650 PG_RETURN_NULL();
651 }
652
655 PG_FREE_IF_COPY(geom, 0);
656 PG_RETURN_POINTER(ret);
657
658}
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)
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)