PostGIS  2.1.10dev-r@@SVN_REVISION@@
int lwline_split_by_point_to ( const LWLINE ln,
const LWPOINT pt,
LWMLINE to 
)

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 161 of file lwgeom_geos_split.c.

References getPoint4d_p(), lwline_construct(), lwmline_add_lwline(), POINTARRAY::npoints, LWPOINT::point, LWLINE::points, ptarray_free(), ptarray_length_2d(), ptarray_locate_point(), ptarray_substring(), and SRID_UNKNOWN.

Referenced by lwgeom_node(), lwline_split_by_point(), and test_lwline_split_by_point_to().

163 {
164  double loc, dist;
165  POINT4D pt, pt_projected;
166  POINTARRAY* pa1;
167  POINTARRAY* pa2;
168  double vstol; /* vertex snap tolerance */
169 
170  /* Possible outcomes:
171  *
172  * 1. The point is not on the line or on the boundary
173  * -> Leave collection untouched, return 0
174  * 2. The point is on the boundary
175  * -> Leave collection untouched, return 1
176  * 3. The point is in the line
177  * -> Push 2 elements on the collection:
178  * o start_point - cut_point
179  * o cut_point - last_point
180  * -> Return 2
181  */
182 
183  getPoint4d_p(blade_in->point, 0, &pt);
184  loc = ptarray_locate_point(lwline_in->points, &pt, &dist, &pt_projected);
185 
186  /* lwnotice("Location: %g -- Distance: %g", loc, dist); */
187 
188  if ( dist > 0 ) /* TODO: accept a tolerance ? */
189  {
190  /* No intersection */
191  return 0;
192  }
193 
194  if ( loc == 0 || loc == 1 )
195  {
196  /* Intersection is on the boundary */
197  return 1;
198  }
199 
200  /* There is a real intersection, let's get two substrings */
201 
202  /* Compute vertex snap tolerance based on line length
203  * TODO: take as parameter ? */
204  vstol = ptarray_length_2d(lwline_in->points) / 1e14;
205 
206  pa1 = ptarray_substring(lwline_in->points, 0, loc, vstol);
207  pa2 = ptarray_substring(lwline_in->points, loc, 1, vstol);
208 
209  /* NOTE: I've seen empty pointarrays with loc != 0 and loc != 1 */
210  if ( pa1->npoints == 0 || pa2->npoints == 0 ) {
211  ptarray_free(pa1);
212  ptarray_free(pa2);
213  /* Intersection is on the boundary */
214  return 1;
215  }
216 
219  return 2;
220 }
int npoints
Definition: liblwgeom.h:327
void ptarray_free(POINTARRAY *pa)
Definition: ptarray.c:315
POINTARRAY * ptarray_substring(POINTARRAY *pa, double d1, double d2, double tolerance)
start location (distance from start / total distance) end location (distance from start / total dist...
Definition: ptarray.c:1022
double ptarray_length_2d(const POINTARRAY *pts)
Find the 2d length of the given POINTARRAY (even if it's 3d)
Definition: ptarray.c:1586
LWMLINE * lwmline_add_lwline(LWMLINE *mobj, const LWLINE *obj)
Definition: lwmline.c:33
double ptarray_locate_point(const POINTARRAY *pa, const POINT4D *pt, double *dist, POINT4D *p_located)
Definition: ptarray.c:1267
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:29
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:154
int getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point)
Definition: lwgeom_api.c:217

Here is the call graph for this function:

Here is the caller graph for this function: