Take in a LINESTRING and return a MULTILINESTRING of those portions of the LINESTRING between the from/to range for the specified ordinate (XYZM)
529{
533 uint32_t i;
534 int added_last_point = 0;
535 POINT4D *p = NULL, *q = NULL, *
r = NULL;
536 double ordinate_value_p = 0.0, ordinate_value_q = 0.0;
537 char hasz, hasm;
538 char dims;
539
540
541 assert(line);
545
546
547 if ((ordinate == 'Z' && !hasz) || (ordinate == 'M' && !hasm))
548 {
549 lwerror(
"Cannot clip on ordinate %d in a %d-d geometry.", ordinate, dims);
550 return NULL;
551 }
552
553
557
558
560
561
563
564 for (i = 0; i < pa_in->
npoints; i++)
565 {
566 if (i > 0)
567 {
568 *q = *p;
569 ordinate_value_q = ordinate_value_p;
570 }
573
574
575 if (ordinate_value_p >= from && ordinate_value_p <= to)
576 {
577
578 if (!added_last_point)
579 {
580
581
583
584
585
586
587
588 if (i > 0 &&
589 (
590 (ordinate_value_p > from && ordinate_value_p < to) ||
591 (ordinate_value_p == from && ordinate_value_q > to) ||
592 (ordinate_value_p == to && ordinate_value_q < from)))
593 {
594 double interpolation_value;
595 (ordinate_value_q > to) ? (interpolation_value = to)
596 : (interpolation_value = from);
599 }
600 }
601
603 if (ordinate_value_p == from || ordinate_value_p == to)
604 added_last_point = 2;
605 else
606 added_last_point = 1;
607 }
608
609 else
610 {
611 if (added_last_point == 1)
612 {
613
614
615 double interpolation_value;
616 (ordinate_value_p > to) ? (interpolation_value = to) : (interpolation_value = from);
619 }
620 else if (added_last_point == 2)
621 {
622
623
624
625 if (from != to && ((ordinate_value_q == from && ordinate_value_p > from) ||
626 (ordinate_value_q == to && ordinate_value_p < to)))
627 {
628 double interpolation_value;
629 (ordinate_value_p > to) ? (interpolation_value = to)
630 : (interpolation_value = from);
633 }
634 }
635 else if (i && ordinate_value_q < from && ordinate_value_p > to)
636 {
637
638
640
643
646 }
647 else if (i && ordinate_value_q > to && ordinate_value_p < from)
648 {
649
650
652
655
658 }
659
660 if (dp)
661 {
662
663
665 {
669 }
670 else
671 {
674 }
675
676
677 dp = NULL;
678 }
679 added_last_point = 0;
680 }
681 }
682
683
684 if (dp)
685 {
687 {
691 }
693 {
696 }
697 else
699 }
700
704
707
708 return lwgeom_out;
709}
void lwgeom_refresh_bbox(LWGEOM *lwgeom)
Drop current bbox and calculate a fresh one.
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
LWPOINT * lwpoint_construct(int32_t srid, GBOX *bbox, POINTARRAY *point)
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
void * lwalloc(size_t size)
LWLINE * lwline_construct(int32_t srid, GBOX *bbox, POINTARRAY *points)
#define FLAGS_NDIMS(flags)
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
void ptarray_free(POINTARRAY *pa)
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int32_t srid, char hasz, char hasm)
int ptarray_append_point(POINTARRAY *pa, const POINT4D *pt, int allow_duplicates)
Append a point to the end of an existing POINTARRAY If allow_duplicate is LW_FALSE,...
LWCOLLECTION * lwcollection_add_lwgeom(LWCOLLECTION *col, const LWGEOM *geom)
Appends geom to the collection managed by col.
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
void ptarray_set_point4d(POINTARRAY *pa, uint32_t n, const POINT4D *p4d)
POINTARRAY * ptarray_construct(char hasz, char hasm, uint32_t npoints)
Construct an empty pointarray, allocating storage and setting the npoints, but not filling in any inf...
void void lwerror(const char *fmt,...) __attribute__((format(printf
Write a notice out to the error handler.
double lwpoint_get_ordinate(const POINT4D *p, char ordinate)
Given a POINT4D and an ordinate number, return the value of the ordinate.
int point_interpolate(const POINT4D *p1, const POINT4D *p2, POINT4D *p, int hasz, int hasm, char ordinate, double interpolation_value)
Given two points, a dimensionality, an ordinate, and an interpolation value generate a new point that...