Question

I am trying to store Geo CoOrdinates inside mysql database Server. If my Coordinate precision value exceeds 15 digit then the value getting rounding off and get stored in the database. I believe it is happening because of this doc.

But interesting info is When I have tried to store the same coordinates with the double datatype. I can able to store upto 17 digit precision.

Spatial Data types also storing each coordinates as a double by inside. Then Why The Spatial datatype can not store more than 15 digit precision ? I have to store upto 20 digit precision What to do now?

Was it helpful?

Solution

Its a good question and perhaps someone with a greater knowledge of the internals could answer this, however, I personally would question why you "have to store up to 20 digit precision".

I've noticed from some of your previous questions that you're dealing with latitude and longitude coordinates, is this still correct?

Assuming so, the need for 20 digit precision is questionable, and with good reason. A single degree of longitude at the equator (it's largest) represents approximately 110km. Therefore:

  • 1 decimal place is 11 kilometres
  • 2 decimal places is 1.1 kilometres
  • 3 decimal places is 110 metres
  • 4 decimal places is 11 metres
  • 5 decimal places is 1.1 metres
  • 6 decimal places is 11 centimetres
  • 7 decimal places is 1.1 centimetres
  • 8 decimal places is 1.1 millimetres
  • 9 decimal places is 0.11 millimetres
  • 10 decimal places is 0.011 millimetres

.. I don't think I need to continue here, at 20 decimal places you'll be dealing with distances way smaller than nanometre scale. It's worth noting that in reality these distances reduce as you get closer to the poles although with MySQL you're working on a planar model so this doesn't apply (unless you manually implement the complicated vincenty algorithm to calculate distances - which carries severe overhead in comparison to the haversine method). There is also no equipment on this earth that records this accurately and therefore you'll never achieve a "absolute" result at those levels.

Even if you're not working with latitude and longitude and you're working with Geometry on a planar model, your units can be whatever measurement you want them to be (as long as you remember, convert as necessary and document it - for example metres) and again, 20 digits of precision are just not required.

Of course, you could drop the use of Spatial altogether and manually implement types with latitude and longitudes stored using a type that supports the required precision. But then you'll have massive overhead of having to implement all of your own calculations AND destroy an benefit to be had from spatial indexing. I do NOT recommend this approach, nor re-inventing the wheel.

Hope that makes sense. If I'm missing something, please feel free to drop a comment and I will update my answer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top