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

Increase GeoJSON precision #306

Merged
merged 1 commit into from
Jun 22, 2018

Conversation

gorunovanton
Copy link
Contributor

I've increased precision when working with GeoJSON due to false-positive polygon self-intersection in scenarios with two close points.

Dataset with false-positive self-intersection:
false_self_intersection.txt

@codeofsumit
Copy link
Contributor

oh wow, thanks for your work on this! I can't seem to find documentation about the parameter passed to toGeoJSON - can you provide a link?

@themre
Copy link
Contributor

themre commented Jun 21, 2018

very nice! perhaps put this in some constant so it can be override via settings?

@codeofsumit
Copy link
Contributor

great idea @themre

@themre
Copy link
Contributor

themre commented Jun 21, 2018

found reference to this precision parameter. we need to make sure from which version is this available:
https://github.com/Leaflet/Leaflet/blob/88dd22cfe89a209d19c061a813e99669844a921b/src/layer/GeoJSON.js#L292

@gorunovanton
Copy link
Contributor Author

There is no information about a precision argument in the official Leaflet documentation of the .toGeoJson() method.

But i've found a pull request with it which was merged around one year ago into the Leaflet codebase:
Leaflet/Leaflet#5444

I don't think that putting this value into a constant is necessary due to how floating point operations are implemented in JS - JS always operates on FP numbers as double precision numbers and 15 is the amount of most significant digits in double precision numbers. This opinion based on two SO topics:
https://stackoverflow.com/questions/1458633/how-to-deal-with-floating-point-number-precision-in-javascript/3644302#3644302
https://stackoverflow.com/questions/28045787/how-many-decimal-places-does-the-primitive-float-and-double-support

@gorunovanton
Copy link
Contributor Author

found that support of this parameter was added in Leaflet 1.1.0:
https://github.com/Leaflet/Leaflet/tree/v1.1.0

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

Successfully merging this pull request may close these issues.

3 participants