[OSM-dev] quadtile Oneliner

Joachim Zobel jz-2008 at heute-morgen.de
Tue Sep 23 20:47:19 BST 2008


Hi.

Just in case nobody found this yet, here is a trick to compute a
quadtile in a single expression. The essence is to convert to the binary
representation (base 2) and interpret it as base 4. This inserts all the
0s between the bits. The rest is simple.

 (CONV(BIN(FLOOR(0.5 + 65535*(longitude/10000000+180)/360)), 4, 10)<<1) 
| CONV(BIN(FLOOR(0.5 + 65535*(latitude/10000000+90)/180)), 4, 10)

The above is using MySQL functions, but the same trick should work in
any language.

The SELECT below has been run as a test against a database containing
europe loaded with osmosis without returning any rows.

   SELECT latitude, longitude, tile,
           (CONV(BIN(FLOOR(0.5 
              + 65535*(longitude/10000000+180)/360)), 4, 10)<<1) 
          | CONV(BIN(FLOOR(0.5 
              + 65535*(latitude/10000000+90)/180)), 4, 10)  
             AS comp_tile
     FROM current_nodes
    WHERE tile <> (CONV(BIN(FLOOR(0.5 
                    + 65535*(longitude/10000000+180)/360)), 4, 10)<<1) 
                 | CONV(BIN(FLOOR(0.5 
                    + 65535*(latitude/10000000+90)/180)), 4, 10) 


Sincerely,
Joachim






More information about the dev mailing list