I have in my MySQL database both longitude and latitude coordinates (GPS data).
It's currently stored as:
column type ------------------------ geolat decimal(10,6) geolng decimal(10,6)
Question: Do I really need a data type as large as decimal(10,6)
to properly store coordinate data?
Since I have a combined index on the longitude and latitude, this index size is huge. If I can make it smaller without compromising anything, that would be great.
Longitude and latitude coordinates are stored with 15 decimal digits right of the decimal points.
Most GPS devices provide coordinates in the Degrees, Minutes and Seconds (DMS) format, or most commonly the Decimal Degrees (DD) format.
Storing Latitude & Longitude data as Floats or Decimal This is one of the most fundamental ways of storing geocoordinate data. Latitude & longitude values can be represented & stored in a SQL database using decimal points (Decimal degrees) rather than degrees (or Degrees Minutes Seconds).
WGS84 datum are usually given as coordinates in a fully decimal notation, usually with 5 decimal places, so for latitude (-90 to +90) you could use decimal(7, 5) (-90.00000 to 90.00000), for longitude you could use decimal(8, 5) (-180.00000 to 180.00000).
.00001 gives an precision of around a meter at the equator
The DECIMAL/NUMERIC data type is a fixed precision scaled integer and both positive and negative parts of the range are always available - they do not affect the precision or scale (there is obviously storage required for it, but you don't get a choice about that for DECIMAL)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With