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.
557 int added_last_point = 0;
558 POINT4D *p = NULL, *q = NULL, *
r = NULL;
559 double ordinate_value_p = 0.0, ordinate_value_q = 0.0;
567 lwerror(
"Null input geometry.");
579 LWDEBUGF(4,
"from = %g, to = %g, ordinate = %c", from, to, ordinate);
583 if ( (ordinate ==
'Z' && ! hasz) || (ordinate ==
'M' && ! hasm) )
585 lwerror(
"Cannot clip on ordinate %d in a %d-d geometry.", ordinate, dims);
600 for ( i = 0; i < pa_in->
npoints; i++ )
603 LWDEBUGF(4,
"added_last_point %d", added_last_point);
607 ordinate_value_q = ordinate_value_p;
611 LWDEBUGF(4,
" ordinate_value_p %g (current)", ordinate_value_p);
612 LWDEBUGF(4,
" ordinate_value_q %g (previous)", ordinate_value_q);
615 if ( ordinate_value_p >= from && ordinate_value_p <= to )
617 LWDEBUGF(4,
" inside ordinate range (%g, %g)", from, to);
619 if ( ! added_last_point )
621 LWDEBUG(4,
" new ptarray required");
631 ( ordinate_value_p > from && ordinate_value_p < to ) ||
632 ( ordinate_value_p == from && ordinate_value_q > to ) ||
633 ( ordinate_value_p == to && ordinate_value_q < from ) ) )
635 double interpolation_value;
636 (ordinate_value_q > to) ? (interpolation_value = to) : (interpolation_value = from);
639 LWDEBUGF(4,
"[0] interpolating between (%g, %g) with interpolation point (%g)", ordinate_value_q, ordinate_value_p, interpolation_value);
644 if ( ordinate_value_p == from || ordinate_value_p == to )
646 added_last_point = 2;
650 added_last_point = 1;
656 LWDEBUGF(4,
" added_last_point (%d)", added_last_point);
657 if ( added_last_point == 1 )
661 double interpolation_value;
662 (ordinate_value_p > to) ? (interpolation_value = to) : (interpolation_value = from);
665 LWDEBUGF(4,
" [1] interpolating between (%g, %g) with interpolation point (%g)", ordinate_value_q, ordinate_value_p, interpolation_value);
667 else if ( added_last_point == 2 )
673 (ordinate_value_q == from && ordinate_value_p > from) ||
674 (ordinate_value_q == to && ordinate_value_p < to) ) )
676 double interpolation_value;
677 (ordinate_value_p > to) ? (interpolation_value = to) : (interpolation_value = from);
680 LWDEBUGF(4,
" [2] interpolating between (%g, %g) with interpolation point (%g)", ordinate_value_q, ordinate_value_p, interpolation_value);
683 else if ( i && ordinate_value_q < from && ordinate_value_p > to )
695 else if ( i && ordinate_value_q > to && ordinate_value_p < from )
710 LWDEBUG(4,
"saving pointarray to multi-line (1)");
730 added_last_point = 0;
738 LWDEBUG(4,
"saving pointarray to multi-line (2)");
762 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_FALSE, 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)