RBush deals incorrectly with search and line strings
wiresong opened this issue · comments
- Turf: 6.5.0
- geojson-rbush: 3.2.1
The following code:
r = require('@turf/geojson-rbush');
turf = require('@turf/turf');
a = r();
a.insert(turf.lineString([[1, 1], [3, 3]]));
a.search(turf.point([1, 2]));
Incorrectly returns the line string as a feature which intersects with the point, when the line string does not in fact include the point. It seems that all the points from (1, 1) to (3, 3) get mistakenly reported as points which intersect the line.
To my understanding RBush uses bounding boxes:
RBush is a high-performance JavaScript library for 2D spatial indexing of points and rectangles
RBush will create a bounding box around the linestring and hence the point will intersect with it.
For the use case you're describing here's some ideas to try:
- If you need to check that a point is in a linestring you can iterate through the linestring coordinates and check if the point coordinate matches
- If you need to check a point is on a linestring, you can try booleanPointOnLine