<br>I've become confused... - for longitude, the world is -180 to +180. Dividing the tiles down by halves gives you 90, 45, 22.5, etc., etc - I don't follow where this is irrational? Or, to make things easier, I've usually tended to scale the world to be (0,0)->(1,1).
<br><br>I'm not even trying to do a float->int conversion (and I'm not sure there is one to interleave the bits without some fairly aggregious bit munging afterwards).<br><br>(x,y) conversion to arbitary QT location is just
<br>  String convert(double x, double y,int numberOfQtPositionsRequired)<br>  {<br>      final String lookup = "abcd"; // tl tr bl br<br>      String result = "";<br>      while((--numberOfQtPositionsRequired) > 0)
<br>      {<br>        x -= Math.floor(x);<br>        y -= Math.floor(y);<br>        <br>        char c = lookup.charAt((x >= 0.5 ? 1 : 0) + (y >= 0.5 ? 2 : 0));<br>        quad = quad + c;<br>                                      
<br>        // now descend into that square<br>        x *= 2;<br>        y *= 2;<br>      }<br>      return result;<br>  }<br><br><div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br><br>Let me explain; If we use two 32 bit ints to represent lat and lon, we<br>could split the globe into 4.2949673Bn angular increments. Of course,<br>this gives us best value in terms of precision for the bits available.
<br>However, this is at the expense of making conversion from degree to int<br>and int to degree reliant on multiplying with a floating point<br>irrational number coefficient. In the GPX trace table, I have foregone a<br>
small degree of the available precision (about 2mm for any location on<br>the planet's surface) to use a decimal integer coefficient - 10000000<br>instead of 11930464.711111111 recurring.<br><br>The 1E7 coefficient makes conversion to/from degrees totally intuitive,
<br>clean and fast. Hopefully, programmers to the API would be inclined to<br>use integer increments of 100nD (nanodegree) as provided by the 1E7<br>coefficient.<br><br>If we were to sub-divide the world in equal quarters from the start, we
<br>will end up with values which do not fit the 1E7 coefficient. I<br>therefore suggest the quadtile function at bits 3 and 4 represents an<br>asymmetric division. On the face of it this may seem messy, but it is<br>really neat and clean, and makes degree based calculation easier and faster.
<br><br>The first two bits represent sign for lat/lon. This naturally divides<br>the world into quarters. But then, for the value to fit into the 1E7<br>coefficient, we simply interleave the integer 1E-7 degree value. Bingo!
<br>That's it. It is very clean and easy to convert using degrees.<br><br> From the freethepostcode database let's use a worked example:<br>51.523343 -0.135136 WC1E 6JL<br><br>Multiply with the 1E7 coefficient and make integer positive. Note the
<br>sign for later.<br><br>S=0       _LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL<br>515233430 00011110101101011101011010010110<br><br>s=1       _lllllllllllllllllllllllllllllll<br>1351360   00000000000101001001111011000000<br><br>Loose the MSB (which would otherwise be a sign bit) then interleave:
<br><br>Capital = Lat Lower=Lon<br>s|S=sign bit<br>l|L=binary values from above<br><br>For an exact location, we get a 64 bit tile reference locating the<br>object to within about 1cm<br>SsLlLlLlLlLlLlLlLlLlLlLlLlLlLlLlLlLlLlLlLlLlLlLlLlLlLlLlLlLlLlLl
<br>0100001010101000100010110011001011100011011111001101001000101000<br><br>If we just take the first 32 bits, we get a 655m tile containing the object:<br>01000010101010001000101100110010<br><br>If we add the rest of the number into the object, we get the complete
<br>location:<br>11100011011111001101001000101000<br><br>Of course, everything works as per wiki page examples, but part of the<br>number ranges will be invalid by using the 1E7 coefficient. In<br>visualisation terms, some tile will disappear along a fold in each
<br>quadrant but for all workable mathematical or computing examples, this<br>would be irrelevant and makes for a very obvious conversion function and<br>consequently, potential widespread use of integer 100nD increments with
<br>associated computational savings.<br><br><br><br><br><br><br>Nigel Magnay wrote:<br>> Ok - I suspect I'm not explaining myself terribly well and the threading<br>> gets a bit lost on emails. I have set up the following page on the Wiki:
<br>><br>> <a href="http://wiki.openstreetmap.org/index.php/QuadTiles">http://wiki.openstreetmap.org/index.php/QuadTiles</a><br>> <<a href="http://wiki.openstreetmap.org/index.php/QuadTiles">http://wiki.openstreetmap.org/index.php/QuadTiles
</a>><br>><br>> I have tried to explain why I think tile addressing is essential, and<br>> why it ought to be a quadtree implementation and not a simple<br>> tile-addressing scheme, and some details of how it might work in practice.
<br>><br>> Whether the address is packed into a 32 or 64-bit integer isn't really<br>> that important in comparison. I have a suspicion that it will actually<br>> be slower than just using fixed char arrays, but - I don't know mysql
<br>> that well, and it's totally amenable to experimentation and metric<br>> gathering.<br>><br>> I'd like to see it in (an|the) API. I don't think it'd be that hard, but<br>> it might make sense to resolve the current status of segments at the
<br>> same time.<br>><br></blockquote></div><br>