Take in a LINESTRING and return a MULTILINESTRING of those portions of the LINESTRING between the from/to range for the specified ordinate (XYZM)
541{
545 uint32_t i;
546 int added_last_point = 0;
547 POINT4D *p = NULL, *q = NULL, *
r = NULL;
548 double ordinate_value_p = 0.0, ordinate_value_q = 0.0;
549 char hasz, hasm;
550 char dims;
551
552
553 assert(line);
557
558
559 if ((ordinate == 'Z' && !hasz) || (ordinate == 'M' && !hasm))
560 {
561 lwerror(
"Cannot clip on ordinate %d in a %d-d geometry.", ordinate, dims);
562 return NULL;
563 }
564
565
569
570
572
573
575
576 for (i = 0; i < pa_in->
npoints; i++)
577 {
578 if (i > 0)
579 {
580 *q = *p;
581 ordinate_value_q = ordinate_value_p;
582 }
585
586
587 if (ordinate_value_p >= from && ordinate_value_p <= to)
588 {
589
590 if (!added_last_point)
591 {
592
593
595
596
597
598
599
600 if (i > 0 &&
601 (
602 (ordinate_value_p > from && ordinate_value_p < to) ||
603 (ordinate_value_p == from && ordinate_value_q > to) ||
604 (ordinate_value_p == to && ordinate_value_q < from)))
605 {
606 double interpolation_value;
607 (ordinate_value_q > to) ? (interpolation_value = to)
608 : (interpolation_value = from);
611 }
612 }
613
615 if (ordinate_value_p == from || ordinate_value_p == to)
616 added_last_point = 2;
617 else
618 added_last_point = 1;
619 }
620
621 else
622 {
623 if (added_last_point == 1)
624 {
625
626
627 double interpolation_value;
628 (ordinate_value_p > to) ? (interpolation_value = to) : (interpolation_value = from);
631 }
632 else if (added_last_point == 2)
633 {
634
635
636
637 if (from != to && ((ordinate_value_q == from && ordinate_value_p > from) ||
638 (ordinate_value_q == to && ordinate_value_p < to)))
639 {
640 double interpolation_value;
641 (ordinate_value_p > to) ? (interpolation_value = to)
642 : (interpolation_value = from);
645 }
646 }
647 else if (i && ordinate_value_q < from && ordinate_value_p > to)
648 {
649
650
652
655
658 }
659 else if (i && ordinate_value_q > to && ordinate_value_p < from)
660 {
661
662
664
667
670 }
671
672 if (dp)
673 {
674
675
677 {
681 }
682 else
683 {
686 }
687
688
689 dp = NULL;
690 }
691 added_last_point = 0;
692 }
693 }
694
695
696 if (dp)
697 {
699 {
703 }
705 {
708 }
709 else
711 }
712
716
719
720 return lwgeom_out;
721}
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 lwerror(const char *fmt,...)
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...