Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

possible bug in lineSlice and nearestPointOnLine #2234

Closed
xobjects opened this issue Dec 13, 2021 · 1 comment · Fixed by #2717
Closed

possible bug in lineSlice and nearestPointOnLine #2234

xobjects opened this issue Dec 13, 2021 · 1 comment · Fixed by #2717

Comments

@xobjects
Copy link

xobjects commented Dec 13, 2021

turf version: 6.5.0

I have an application where given an linestring i need a part (slice) of it, from the beginning to some point. Ultimately I need the distance of the slice of the line. However, there are points that do not work. Both nearestPointOnLine and lineSlice are failing. I show

Below is an example along with the results.

let v_cs_ls_p1 = [-64.371054, 25.604782];
let v_cs_ls_p2 = [-19.65732, 45.178866];
let v_cs_ls = turf.lineString([v_cs_ls_p1, v_cs_ls_p2]);

let v_point_on_line = [-58.26491343728603, 28.5528852825411];

let v_point_on_line_adjusted = turf.nearestPointOnLine(v_cs_ls, v_point_on_line, { units: 'meters' });

v_point_on_line is on the line, but I call nearestPointOnLine anyway and it returns

v_point_on_line_adjusted
{type: 'Feature', properties: {…}, geometry: {…}}
geometry: {type: 'Point', coordinates: Array(2)}
coordinates: (2) [-64.371054, 25.604782]
type: 'Point'
__proto__: Object
properties: {dist: 687546.939020373, index: 0, location: 0}
type: 'Feature'
__proto__: Object

as you can see, it thinks the distance is 687546 meters from the line and returns the point which it believes is the nearest which, in this case, is the start point of the line.

The distance should almost be zero (0) if not zero.

to me this seems like a problem, if this is my mistake then fine. Please show me.

update: i ran several other tests and this only appears to happen on really long lines. Long is subjective I know, but long in this case maybe mean earth factors in. Not sure.

@smallsaucepan
Copy link
Member

Hi @xobjects. Realise it's been a while since you reported this, though in case it's still of interest, I have some comments and some news.

v_point_on_line is on the line

First issue, this is on a line, though not the one Turf is using. That point looks ok projected on a 2D map. When tracing that line on a 3D globe though it looks more like the red line below:

Screenshot 2024-09-21 at 11 36 50 AM

but I call nearestPointOnLine anyway and it returns ... 687546 ... the start point of the line

All that said, nearestPointOnLine wasn't doing the 3D calculation correctly with the red line either. The closest point to v_point_on_line on the great circle line is at [ -59.06380751636502, 29.452900049382293 ] and about 675817m away. That's the red point on the map below:

Screenshot 2024-09-21 at 11 52 19 AM

A fix for the nearestPointOnLine issue is on its way. If you still have an interest in this, can you please elaborate a bit more on the lineSlice issues you were having? Some flow on changes to lineSlice are coming too, so it would be good to make sure they address any issues you had in that regard as well.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants