[OSM-dev] Osmosis Bug Report: Node TileIDs Incorrect

Tom Hughes tom at compton.nu
Sun Apr 27 12:34:10 BST 2008


In message <5027E631-61B5-49BD-8E21-C08C29F119A2 at shaunmcdonald.me.uk>
          Shaun McDonald <shaun at shaunmcdonald.me.uk> wrote:

> On 27 Apr 2008, at 11:38, Brett Henderson wrote:
> 
> >        //x = (int) Math.round((longitude + 180) * 65536 / 360);
> >        //y = (int) Math.round((latitude + 90) * 65536 / 180);
> >        x = (int) Math.floor((longitude + 180) * 65536 / 360);
> >        y = (int) Math.floor((latitude + 90) * 65536 / 180);
> 
> Taking a look at rails:
> http://trac.openstreetmap.org/browser/sites/rails_port/lib/quad_tile.rb#L6
> it appears that the ruby library is using round too. However, more
> importantly, they use 65535, while you have been using 65536. Being 1
> out could throw this. Try that change and see if it helps.

Yep - the input (after adjusting to zero) is between 0 and 360 (for
the longitude) or 0 and 180 (for the latitude) and we want to produce
a 16 bit integer so the result needs be between 0 and 65535 or we will
overflow sometimes.

So 65535 is the correct multiplier, not 65536. After that rounding is
the correct thing to do rather than truncating. That is what both the
ruby version that Shaun quoted and the C version do:

http://trac.openstreetmap.org/browser/sites/rails_port/lib/quad_tile/quad_tile.h

Tom

-- 
Tom Hughes (tom at compton.nu)
http://www.compton.nu/




More information about the dev mailing list