views:

261

answers:

7

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.

A: 

That depends on how precise you want your locatability to be. Obviously the larger the more precise, and the smaller the more broad your results will be. I'd suggest keeping your values larger, as it isn't really much data anyway.

Jonathan Sampson
This is only to store geo-data for house/home location (real estate app). So it doesn't need to be super accurate but close.
teddyk
+1  A: 

I've always worked with six digits after the decimal. I used to do GIS work under a military contract and this was sufficient.

Steve Elmer
So, are you saying that I could change it to "decimal(6,6)" and be alright?
teddyk
But as Jonathan notes, it really does depend on how precise you want. From my understanding, the six digit precision got us down to somewhere around +/- 1 meter. This was important because we were keeping track of bunkers full of chemical weapons.
Steve Elmer
I believe the "10" is the size of the whole field, isn't it? You will need to accommodate +/- xxx.xxxxxx for longitude and +/- xx.xxxxxx for latitude.
Steve Elmer
This is for a real estate application where we want to store the location of your houses/homes. So it doesn't need to be as accurate as +/- 1 meter. Something like +/- 10 meters would probably be acceptable
teddyk
Whoops, you're correct. Decimal(10,6) means - 10 is the size of the whole field, 6 is the # of digits after the decimal point. As such, do you happen to know how much precision decimal(9,5) might give ... or where I could find out
teddyk
+/- 10 meters is pretty big - approx 65ft - when rendering on a map, you might find your house showing up in the middle of the street.
Steve Elmer
@Steve, it looks like I only need 5 digits to have 1 meter of accuracy. Does this look correct to you? --> http://en.wikipedia.org/wiki/Decimal_degrees
teddyk
I defer to Cade Roux's comment, above. We, too, were using the WGS84 datum. Perhaps our resolution was a bit higher than 1 m.You will want to ensure that you are using the same projection/datum information for all of your geospatial data. WGS84 is a very common standard. I have been bitten more than once by a customer providing data that was based on different projection/datum parameters than what I was using.
Steve Elmer
+2  A: 

Keep in mind that it's easier to reduce data than it is to increase data. Usually, increasing data accuracy isn't even possible short of remeasuring. And remeasuring comes at a cost. Knowing nothing else of your situation or the industry, I would say capture as much data/specificity as possible.

The data that you actually use can be culled from this set. If you end up needing a higher degree of specificity, you can always recalculate without remeasuring.

Also, I'm not sure that indexing raw data is the best thing to do since it isn't a discrete set of elements. Creating a table of less accurate/smaller data points would make the indexes much smaller.

Mark Canlas
*Always* ask this sort of question when thinking about storing data: What will it be used for? What precision/range/whatever is needed to accomplish this?
mlo
+3  A: 

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)

Cade Roux
Does the sign (positive/negative) not take up space? meaning, wouldn't "-90.12345" take up 8 digital and not 7
teddyk
Yes, it takes up space in the database, but the space required in the database for a given DECIMAL specification always allows a sign. I'm not familiar with the internal storage requirements of MySQL, but for SQL Server, a decimal takes 5 bytes (1-9 digits)/9 bytes (10-19 digits)/13 bytes (20-28 digits) /17 bytes (29-38 digits) depending on digits of precision specified (it is independent of scale, obviously).
Cade Roux
+1  A: 

if this is for real estate do you really have so many houses that 2 bytes saved per row is going to be that noticeable? I'd keep as much precision as possible unless there was a good reason not to.

jk
I'm more concerned about the size of my index since I have a combined index on both the longitude and latitude. So right now, my index size is decimal(10,6) + decimal(10,6) in size. Which is very large for an index.
teddyk
was going to reply with spatial indexing - but noticed your comment saying you can't use it, hence why you are having these problems.
jk
A: 

The regular GGA sentance in a NMEA Lat/lon output is only 3decimal places roughly 10m resolution at the equator. Some brands add a custom extra digit to give 1m.

4 digit deg.mm mm/1000 is also common.

If you are using high end precision RTK-GPS you might need more places to get mm precision

Martin Beckett
A: 

You can also try storing (and/or working with) your coordinates in different units. One project I worked on, all of our coordinates were in milliarcseconds stored as longs (maybe ints, it's been a couple years). This was done partially for speed and for storage space (this was an embedded system). But the same logic could apply here.

miko