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.
554 int added_last_point = 0;
555 POINT4D *p = NULL, *q = NULL, *
r = NULL;
556 double ordinate_value_p = 0.0, ordinate_value_q = 0.0;
559 #if POSTGIS_DEBUG_LEVEL >= 4
566 lwerror(
"Null input geometry.");
581 #if POSTGIS_DEBUG_LEVEL >= 4
582 LWDEBUGF(4,
"from = %g, to = %g, ordinate = %c", from, to, ordinate);
589 if ( (ordinate ==
'Z' && ! hasz) || (ordinate ==
'M' && ! hasm) )
591 lwerror(
"Cannot clip on ordinate %d in a %d-d geometry.", ordinate, dims);
606 for ( i = 0; i < pa_in->
npoints; i++ )
609 LWDEBUGF(4,
"added_last_point %d", added_last_point);
613 ordinate_value_q = ordinate_value_p;
617 LWDEBUGF(4,
" ordinate_value_p %g (current)", ordinate_value_p);
618 LWDEBUGF(4,
" ordinate_value_q %g (previous)", ordinate_value_q);
621 if ( ordinate_value_p >= from && ordinate_value_p <= to )
623 LWDEBUGF(4,
" inside ordinate range (%g, %g)", from, to);
625 if ( ! added_last_point )
627 LWDEBUG(4,
" new ptarray required");
637 ( ordinate_value_p > from && ordinate_value_p < to ) ||
638 ( ordinate_value_p == from && ordinate_value_q > to ) ||
639 ( ordinate_value_p == to && ordinate_value_q < from ) ) )
641 double interpolation_value;
642 (ordinate_value_q > to) ? (interpolation_value = to) : (interpolation_value = from);
645 LWDEBUGF(4,
"[0] interpolating between (%g, %g) with interpolation point (%g)", ordinate_value_q, ordinate_value_p, interpolation_value);
650 if ( ordinate_value_p == from || ordinate_value_p == to )
652 added_last_point = 2;
656 added_last_point = 1;
662 LWDEBUGF(4,
" added_last_point (%d)", added_last_point);
663 if ( added_last_point == 1 )
667 double interpolation_value;
668 (ordinate_value_p > to) ? (interpolation_value = to) : (interpolation_value = from);
671 LWDEBUGF(4,
" [1] interpolating between (%g, %g) with interpolation point (%g)", ordinate_value_q, ordinate_value_p, interpolation_value);
673 else if ( added_last_point == 2 )
679 (ordinate_value_q == from && ordinate_value_p > from) ||
680 (ordinate_value_q == to && ordinate_value_p < to) ) )
682 double interpolation_value;
683 (ordinate_value_p > to) ? (interpolation_value = to) : (interpolation_value = from);
686 LWDEBUGF(4,
" [2] interpolating between (%g, %g) with interpolation point (%g)", ordinate_value_q, ordinate_value_p, interpolation_value);
689 else if ( i && ordinate_value_q < from && ordinate_value_p > to )
701 else if ( i && ordinate_value_q > to && ordinate_value_p < from )
716 LWDEBUG(4,
"saving pointarray to multi-line (1)");
736 added_last_point = 0;
744 LWDEBUG(4,
"saving pointarray to multi-line (2)");
768 if ( lwgeom_out->
bbox && lwgeom_out->
ngeoms > 0 )
void lwgeom_refresh_bbox(LWGEOM *lwgeom)
Drop current bbox and calculate a fresh one.
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
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...
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an alloced string.
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
#define FLAGS_NDIMS(flags)
LWPOINT * lwpoint_construct(int srid, GBOX *bbox, POINTARRAY *point)
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
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.
void * lwalloc(size_t size)
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
void ptarray_set_point4d(POINTARRAY *pa, uint32_t n, const POINT4D *p4d)
#define LWDEBUG(level, msg)
#define LWDEBUGF(level, msg,...)
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...