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

Add precision parameter to all toGeoJSON functions #5444

Merged
merged 6 commits into from May 31, 2017

Conversation

Projects
None yet
4 participants
@mattgrande
Contributor

mattgrande commented Apr 10, 2017

As recommended in PR #5237. Example usage:

var marker = new L.Marker([10.123456, 20.123456, 30.123456]);
marker.toGeoJSON();    // Works without changes
marker.toGeoJSON(3);   // Restricts all numbers to three significant digits
@perliedman

Hi and thanks a lot for looking into this!

I have three points I'd like to see addressed before merging this:

  • As it is now, the coordinates output by toGeoJSON will be strings, not numbers; for example ["-87.359296", "35.00118"] rather than the expected [-87.359296, 35.00118] - this looks wrong and might possibly trip up some receivers that care about data types; it is also against the RFC 7947 which says: "A position is an array of numbers"
  • The GeoJSON spec gives the precision as number of decimals, while this PR gives the precision as number of significant digits; as it is now, it is not possible to give a number that adheres to the GeoJSON spec's recommendation of six decimals
  • Not necessarily important, but I think it might also be a good idea to default to the GeoJSON specs recommendation, so that we use six decimals unless something else is specified.
@mattgrande

This comment has been minimized.

Show comment
Hide comment
@mattgrande

mattgrande Apr 21, 2017

Contributor

Hmm, looks like toFixed would work better than toPrecision... but that also returns a string, and if I convert to a number, I'm getting weird results. Will continue to look into it.

Contributor

mattgrande commented Apr 21, 2017

Hmm, looks like toFixed would work better than toPrecision... but that also returns a string, and if I convert to a number, I'm getting weird results. Will continue to look into it.

@fminuti

This comment has been minimized.

Show comment
Hide comment
@fminuti

fminuti Apr 21, 2017

Contributor

I think you could use L.Util.formatNum

Contributor

fminuti commented Apr 21, 2017

I think you could use L.Util.formatNum

fminuti added a commit to fminuti/Leaflet that referenced this pull request May 3, 2017

Util.formatNum default to 6
Changed Util.formaNum default to 6 decimails.
Solved 0 decimals bug.
Added tests.
Can be useful for PR Leaflet#5444
@mattgrande

This comment has been minimized.

Show comment
Hide comment
@mattgrande

mattgrande May 24, 2017

Contributor

Sorry for the delay, @perliedman! Those changes you requested are in.

Contributor

mattgrande commented May 24, 2017

Sorry for the delay, @perliedman! Those changes you requested are in.

@ghybs ghybs referenced this pull request May 27, 2017

Closed

Add a precision argument to toGeoJSON method #5237

4 of 4 tasks complete
@perliedman

Looks good! Thanks for finishing this!

@perliedman perliedman merged commit 1120c46 into Leaflet:master May 31, 2017

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

cherniavskii added a commit that referenced this pull request Oct 2, 2017

Change Util.formatNum default to 6 decimals (#5492)
* Util.formatNum default to 6

Changed Util.formaNum default to 6 decimails.
Solved 0 decimals bug.
Added tests.
Can be useful for PR #5444

* Changed documentation

Changed documentation to 6 instead of 5

@timelyportfolio timelyportfolio referenced this pull request Jun 22, 2018

Closed

geojson precision #63

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