Skip to content

possible bug in lineSlice and nearestPointOnLine #2234

@xobjects

Description

@xobjects

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions