Clip a line based on the from/to range of one of its ordinates.
Clip a line based on the from/to range of one of its ordinates.
544 int added_last_point = 0;
545 POINT4D *p = NULL, *q = NULL, *
r = NULL;
546 double ordinate_value_p = 0.0, ordinate_value_q = 0.0;
554 lwerror(
"Null input geometry.");
566 LWDEBUGF(4,
"from = %g, to = %g, ordinate = %c", from, to, ordinate);
570 if ( (ordinate ==
'Z' && ! hasz) || (ordinate ==
'M' && ! hasm) )
572 lwerror(
"Cannot clip on ordinate %d in a %d-d geometry.", ordinate, dims);
587 for ( i = 0; i < pa_in->
npoints; i++ )
590 LWDEBUGF(4,
"added_last_point %d", added_last_point);
594 ordinate_value_q = ordinate_value_p;
598 LWDEBUGF(4,
" ordinate_value_p %g (current)", ordinate_value_p);
599 LWDEBUGF(4,
" ordinate_value_q %g (previous)", ordinate_value_q);
602 if ( ordinate_value_p >= from && ordinate_value_p <= to )
604 LWDEBUGF(4,
" inside ordinate range (%g, %g)", from, to);
606 if ( ! added_last_point )
608 LWDEBUG(4,
" new ptarray required");
618 ( ordinate_value_p > from && ordinate_value_p < to ) ||
619 ( ordinate_value_p == from && ordinate_value_q > to ) ||
620 ( ordinate_value_p == to && ordinate_value_q < from ) ) )
622 double interpolation_value;
623 (ordinate_value_q > to) ? (interpolation_value = to) : (interpolation_value = from);
626 LWDEBUGF(4,
"[0] interpolating between (%g, %g) with interpolation point (%g)", ordinate_value_q, ordinate_value_p, interpolation_value);
631 if ( ordinate_value_p == from || ordinate_value_p == to )
633 added_last_point = 2;
637 added_last_point = 1;
643 LWDEBUGF(4,
" added_last_point (%d)", added_last_point);
644 if ( added_last_point == 1 )
648 double interpolation_value;
649 (ordinate_value_p > to) ? (interpolation_value = to) : (interpolation_value = from);
652 LWDEBUGF(4,
" [1] interpolating between (%g, %g) with interpolation point (%g)", ordinate_value_q, ordinate_value_p, interpolation_value);
654 else if ( added_last_point == 2 )
660 (ordinate_value_q == from && ordinate_value_p > from) ||
661 (ordinate_value_q == to && ordinate_value_p < to) ) )
663 double interpolation_value;
664 (ordinate_value_p > to) ? (interpolation_value = to) : (interpolation_value = from);
667 LWDEBUGF(4,
" [2] interpolating between (%g, %g) with interpolation point (%g)", ordinate_value_q, ordinate_value_p, interpolation_value);
670 else if ( i && ordinate_value_q < from && ordinate_value_p > to )
682 else if ( i && ordinate_value_q > to && ordinate_value_p < from )
697 LWDEBUG(4,
"saving pointarray to multi-line (1)");
717 added_last_point = 0;
725 LWDEBUG(4,
"saving pointarray to multi-line (2)");
749 if ( lwgeom_out->
bbox && lwgeom_out->
ngeoms > 0 )
void ptarray_set_point4d(POINTARRAY *pa, int 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...
double lwpoint_get_ordinate(const POINT4D *p, char ordinate)
Given a POINT4D and an ordinate number, return the value of the ordinate.
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an alloced string.
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
#define LWDEBUG(level, msg)
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...
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
void lwgeom_drop_bbox(LWGEOM *lwgeom)
Call this function to drop BBOX and SRID from LWGEOM.
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
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_TRUE, then a duplicate point will not be added.
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
LWPOINT * lwpoint_construct(int srid, GBOX *bbox, POINTARRAY *point)
void * lwalloc(size_t size)
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
#define LWDEBUGF(level, msg,...)
#define FLAGS_NDIMS(flags)
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
LWCOLLECTION * lwcollection_add_lwgeom(LWCOLLECTION *col, const LWGEOM *geom)
Appends geom to the collection managed by col.
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
int getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point)