Skip to content

@turf/nearestPointOnLine Coordinates must contain numbers #2939

@SimplyPancake

Description

@SimplyPancake

When asking for the nearest point on line with a valid point and a lineString, at some point it returns an error stating that "coordinates must contain numbers".
However, both the lineString and Point have data. After some debugging, it seems that somewhere in the code a variable intersectPos is set. The variable is checked to be null, however there should also be a check if the array of points does not contain Nan numbers.

Image

I recommend that this check would be fixed with something along the lines of

if (
  intersectPos &&
  Array.isArray(intersectPos) &&
  intersectPos.length === 2 &&
  !Number.isNaN(intersectPos[0]) &&
  !Number.isNaN(intersectPos[1])
) {
  intersectPt = point(intersectPos, {
    dist: distance(pt, intersectPos, options),
    multiFeatureIndex: multiFeatureIndex,
    location: length + distance(start, intersectPos, options),
  });
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions