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

turf.truncate without rounding #2834

Open
olsp opened this issue Feb 7, 2025 · 1 comment
Open

turf.truncate without rounding #2834

olsp opened this issue Feb 7, 2025 · 1 comment

Comments

@olsp
Copy link

olsp commented Feb 7, 2025

I would like to compare two GeoJSON Features to find out if they are very similar. I use truncate and then compare the geometry. The problem is, that truncate not just cuts the values at the specified decimal but also rounds.

As an example the values 48.022774 and 48.022775 when truncated to 5 decimals lead to 48.02277 and 48.02278.

Is there a way to disable rouding when using truncate?

@olsp
Copy link
Author

olsp commented Feb 15, 2025

I now also looked at the code. I think it would be good to use Math.trunc() instead of Math.round(). I think the name of the function implicates that the number gets just "cut off", not rounded.
The description in the API says "Takes a GeoJSON Feature or FeatureCollection and truncates the precision of the geometry.". So there is no rounding mentioned. In the provided example in the docs though, 58.11088890802906 becomes 58.111.

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

No branches or pull requests

1 participant