Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How many significant digits should I store in my database for a GPS coordinate?

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.

like image 341
teddyk Avatar asked Dec 22 '09 16:12

teddyk


People also ask

How many digits are needed in GPS coordinates?

Longitude and latitude coordinates are stored with 15 decimal digits right of the decimal points.

What is the standard format for GPS coordinates?

Most GPS devices provide coordinates in the Degrees, Minutes and Seconds (DMS) format, or most commonly the Decimal Degrees (DD) format.

How do you store latitude and longitude in a database?

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).


1 Answers

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)

like image 75
Cade Roux Avatar answered Oct 02 '22 15:10

Cade Roux