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

How to disable rounding decimal coordinates #202

Open
NoharaMasato opened this issue Apr 6, 2023 · 1 comment
Open

How to disable rounding decimal coordinates #202

NoharaMasato opened this issue Apr 6, 2023 · 1 comment

Comments

@NoharaMasato
Copy link
Contributor

Issues

By default DEFAULT_PRECISION = 6 and instantiating Point class rounds decimal number like below.

>>> import geojson
>>> geojson.Point((1e-9, 0))
{"coordinates": [0.0, 0], "type": "Point"}

Proposal

I think decimal numbers should be kept as it is by default , and we can optionally specify precision.
I wonder which kind of use cases people want to round decimal numbers when they use geojson library.

@trcmohitmandokhot
Copy link
Contributor

I've been thinking about this question, which is a good one. I think there are a couple of parts to your question, so I am attempting to break them down the best I can. Please clarify as needed:

  1. When you create a co-ordinate with a value such as Point((1e-9,0)) the 1e-9 is a "Real" number, stored as an object of type "float". Python's native round() function applies on that object and provides a representation of that fraction as best as it can following the rules and limitations of Floating Point Arithmetic.
  2. The geojson instance functions offer a way to change the precision of round function used in python. This will allow you to preserve the decimal coordinates you need. Example...
>>> p = geojson.Point((1e-9,0),precision=9)  
{"coordinates": [1e-09, 0], "type": "Point"}
  1. With regards to why DEFAULT_PRECISION = 6, I believe this has to do with interoperability considerations in the GeoJSON RFC 7946 Sec 11.2. A precision of 6 lies offers a representation of ~10cm in Lat/Lon co-ordinates. This is deemed good enough for major surveying activities, and adequate precision to exchange information in. A very good article was posted on GIS Stackexchange about the impact of precision in GPS coordinates, which someone who is interested can read here

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

2 participants