Database Requirements

The only thing your database really needs to suit working with GMDC is a field called half_degree_index, which is integer, unsigned and indexed. In fact you can call this field what you want, just change the code on the server to select the right field. I am assuming you have latitude, longitude and id fields already, right? :)

In the sample directory there is a sample SQL file that shows the minimum required for a functioning application. A table called sites contains id, latitude, longitude, name and half_degree_index.

The half_degree_index is the key to how this version 1 works, and corresponds to a half degree chunk of data. It is layed out simply as (L)ongitude & l(A)titude : LLLLAAAA. The values are biased so they are not negative (i.e. add 180 to longitude, 90 to latitude) and multiplied by 10. The final digit of each value is however only 5 or 0 - all points are 'chunked' into their respective block. The makes finding the information from the database for a particular chunk very very fast indeed.

Calculating half_degree_index

When you add a new site or modify it's position, you will need to calculate the half_degree_index to make sure your new site is picked up by the chunker (and you must invalidate the cache, remember?). The code for this is very simple, here it is in SQL:

half_degree_index = floor((s_long+180)*2)/2*100000 + floor((s_lat+90)*2)/2*10

You can optimize it by changing the /2*100000 to *50000 and /2*10 to *5, but I've left it in above so you can get the gist of whats going on. (bias the value, then double it. lop off any decimal places, then divide by 2. That will give you a number that is only either x.0 or x.5. Then multiply the value into the correct position)