[OSM-dev] spatial reference

Artem Pavlenko artem at mapnik.org
Mon Jul 2 16:20:26 BST 2007


Hello,

I had a chance to go through tile.openstreetmap.org implementation  
and I'd like to suggest some improvements.

At the moment we store x,y,z and there is a key(x,y,z). I think we  
can improve by introducing spatial reference (also known as quad key  
etc) and this is exactly what MS VE, Oracle and others are using.  
There are a few benefits but the main one is
that standard b-tree index will  'cluster' tiles spatially, resulting  
in better I/O.  It will also simplify and reduce table size a little  
bit.

  x = 32541 y = 21721  z = 16   becomes 'adbdbdbbccaddbad'  // the  
length of this key equals to zoom level.

And there is a simple logic to go to/from (see Python below)

I'm not sure if this has been discussed already, thoughts?

Cheers,
Artem


def spatial_reference ( x , y, zoom):
     ref = ''
     for i in range(zoom,0,-1):
         mask = 1 << (i - 1)
         cell = ord('a')
         if ( x & mask ) != 0 : cell += 1
         if ( y & mask ) != 0 : cell += 2
         ref += chr(cell)
     return ref

if __name__ == '__main__':
     x = 32541
     y = 21721
     z = 16

     ref = spatial_reference(x,y,z)
     print "%s %s %s -> %s" % (x,y,z,ref)
     print "zoom level eq len(ref) e.g. %s" % len(ref)



Artem Pavlenko
http://mapnik.org



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/dev/attachments/20070702/11c2b527/attachment.html>


More information about the dev mailing list