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

Error: coordinates must contain numbers #2809

Open
Felankia opened this issue Jan 13, 2025 · 9 comments
Open

Error: coordinates must contain numbers #2809

Felankia opened this issue Jan 13, 2025 · 9 comments
Assignees

Comments

@Felankia
Copy link

Felankia commented Jan 13, 2025

Version: 7.2.0

Code:

let line = {}; //GeoJSON contant in [https://github.com/user-attachments/files/18392267/geojson.txt]
line = turf.cleanCoords(line);
let grid = turf.polygon([[[105.82001,38.30005],[105.87001,38.30005],[105.87001,38.350049999999996],[105.82001,38.350049999999996],[105.82001,38.30005]]])
turf.lineSplit(line, grid);

Stacktrace:

Error: coordinates must contain numbers
    at point (../node_modules/@turf/helpers/dist/cjs/index.cjs:78:11)
    at ../node_modules/@turf/nearest-point-on-line/dist/cjs/index.cjs:69:40
    at../node_modules/@turf/meta/dist/cjs/index.cjs:255:13
    at geomEach (../node_modules/@turf/meta/dist/cjs/index.cjs:197:15)
    at flattenEach (../node_modules/@turf/meta/dist/cjs/index.cjs:248:3)
    at nearestPointOnLine (../node_modules/@turf/nearest-point-on-line/dist/cjs/index.cjs:42:21)
    at ../node_modules/@turf/turf/node_modules/@turf/line-split/dist/cjs/index.cjs:112:53
    at featureEach (../node_modules/@turf/meta/dist/cjs/index.cjs:148:11)
    at findClosestFeature (../node_modules/@turf/turf/node_modules/@turf/line-split/dist/cjs/index.cjs:111:21)
    at ../node_modules/@turf/turf/node_modules/@turf/line-split/dist/cjs/index.cjs:56:27
@petrot
Copy link

petrot commented Jan 13, 2025

Same problem here with the "nearestPointOnLine" function.

@paulomesquita-wsn
Copy link

I discovered that the problem is related to a line with two consecutive equal coordinates

@osajus
Copy link

osajus commented Jan 14, 2025

In case it helps, I've run into a similar issue. I thought it might have to do with the consecutive equal coordinates as well, but if I remove any of the coordinates in this sample file, the problem resolves itself.
https://jsfiddle.net/nd48h0r7/

@smallsaucepan
Copy link
Member

Likely to be closely related to #2807

@maciejgoscinski-latrace

Same issue for me recently, and I arrived at the same conclusion as @paulomesquita-wsn - this is what happens when two adjacent coords are identical.

Maybe there's a good reason for the function to require deduplicated coords on the input, but in such case it should print a clearer error message, and document this requirement.

Duct-tape-fixed on our end by sanitizing the input geojsons to filter out duplicate coords.

@colinperepelken
Copy link

I also just experienced this. The last two points in my line string were duplicates. The error message is incredibly unhelpful. I used turf.cleanCoords as recommended in this thread and that resolved the issue for me.

@smallsaucepan
Copy link
Member

Thanks @colinperepelken. What would make the error more helpful to you? Including the value of the invalid coordinate in the message?

@colinperepelken
Copy link

@smallsaucepan Currently the error is "Error: coordinates must contain numbers", which is confusing because when I checked all of my input coordinates to nearestPointOnLine did contain numbers.

Something like "Error: coordinates contain duplicates, use cleanCoords to remove them". Or better yet, can this just not throw an error, or remove the duplicates automatically?

@smallsaucepan
Copy link
Member

Or better yet, can this just not throw an error, or remove the duplicates automatically?

Oh definitely, we'll fix the condition that caused the original problem. The error message that pops up is thrown in a lower level function though, so it's not able to tell why the coordinates weren't numbers.

Will see what we can do to improve both aspects 👍

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

No branches or pull requests

7 participants