Split a line by a point and push components to the provided multiline.
If the point doesn't split the line, push nothing to the container. Returns 0 if the point is off the line. Returns 1 if the point is on the line boundary (endpoints). Return 2 if the point is on the interior of the line (only case in which a split happens).
NOTE: the components pushed to the output vector have their SRID stripped
Definition at line 209 of file lwgeom_geos_split.c.
References closest_point_on_segment(), distance2d_pt_seg(), POINTARRAY::flags, FLAGS_GET_M, FLAGS_GET_Z, getPoint4d_p(), LW_FALSE, LWDEBUGF, lwline_construct(), lwmline_add_lwline(), POINTARRAY::npoints, p4d_same(), LWPOINT::point, LWLINE::points, ptarray_append_point(), ptarray_construct_empty(), ptarray_free(), SRID_UNKNOWN, POINT2D::x, POINT4D::x, POINT2D::y, and POINT4D::y.
Referenced by lwgeom_node(), lwline_split_by_mpoint(), lwline_split_by_point(), and test_lwline_split_by_point_to().
218 int i, nsegs, seg = -1;
238 for ( i = 0; i < nsegs; i++ )
243 LWDEBUGF(4,
" Distance of point %g %g to segment %g %g, %g %g: %g", pt.
x, pt.
y, p1.
x, p1.
y, p2.
x, p2.
y, dist);
244 if (i==0 || dist < mindist )
248 if ( mindist == 0.0 )
break;
253 LWDEBUGF(3,
"Closest segment: %d", seg);
254 LWDEBUGF(3,
"mindist: %g", mindist);
257 if ( mindist > 0 )
return 0;
260 if ( seg < 0 )
return 1;
274 pt_projected.
x = pt.
x;
275 pt_projected.
y = pt.
y;
277 LWDEBUGF(3,
"Projected point:(%g %g), seg:%d, p1:(%g %g), p2:(%g %g)", pt_projected.
x, pt_projected.
y, seg, p1.
x, p1.
y, p2.
x, p2.
y);
280 if ( ( (seg == nsegs-1) &&
p4d_same(&pt_projected, &p2) ) ||
281 ( (seg == 0) &&
p4d_same(&pt_projected, &p1) ) )
290 for (i=0; i<=seg; ++i)
300 for (i=seg+1; i<ipa->
npoints; ++i)
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
void ptarray_free(POINTARRAY *pa)
LWMLINE * lwmline_add_lwline(LWMLINE *mobj, const LWLINE *obj)
double distance2d_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B)
The old function nessecary for ptarray_segmentize2d in ptarray.c.
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)
#define SRID_UNKNOWN
Unknown SRID value.
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
#define FLAGS_GET_M(flags)
void closest_point_on_segment(const POINT4D *R, const POINT4D *A, const POINT4D *B, POINT4D *ret)
#define LWDEBUGF(level, msg,...)
int getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point)
int p4d_same(const POINT4D *p1, const POINT4D *p2)