[OSM-talk] calculating lon/lat bounds from tilename

Ralf Zimmermann Ralf at Zimmermann.com
Fri Jun 22 18:51:14 BST 2007


Daniel Would wrote:
 > Hi, not sure if this is the right place to post this question, so
 > forgive me if it's off topic...
 > I've been working on a script that takes a lon/lat position, zoom level
 > and a size of grid to capture.
 > and it retrieves all the tiles in a grid of your size centered around
 > the lon/lat provided.
 > so I might say zoom=15, gridsize=4 and it will get me a 4x4 grid of
 > tiles at that zoom level around my lon/lat.
 > Now I'm doing this to use with TrekBuddy which is very cool. And I want
 > a script that will build me the Atlas inputs it requires using the
 > openstreetmap images.
 > Everything works great.. however I need to generate a file that
 > specifies the lon/lat of the top left corner and bottom right corner of
 > my grid. I have no idea how to do that (I stole the calculation for
 > lon/lat -> mercator tile from the osm page that contained a perl
 > example.


I was following the same idea a few weeks ago.
The issue that stopped me from following this path is the following:

If you download tiles from OSM, you will find that the scale in 
North/South direction of the tiles will change with different y values 
of the tiles. This is a specialty of the like-Google way of doing tiles.

 > ... however I need to generate a file that
 > specifies the lon/lat of the top left corner and bottom right corner
 > of my grid.

I think you have the same misunderstanding that I had:

If you download lots of OSM tiles and re-assemble them as a nice 
picture, then you would need the longitude of the left and right side of 
the assembled picture. This is according to your idea.

But for North/South, you would need the upper/lower latitude of every 
row of tiles that you are using - because the scale changes.
So the problem is a bit more complex than you might have thought.

In order to have large areas of OSM data geo-referenced with just 
geo-referencing the upper-left and lower-right corner (4 values), I am 
currently using plain OSM data and then rendering it via osmarender. 
That way, I am bringing the maps onto my Palm PDA, using Pathaway for 
using the maps.


higgy at bandnet.org wrote:
> Unfortunately I never bothered to make the map browser very intuitive
> (worksforme) and I think there's a bug in my lat/lon conversion because my
> position always seems to be slightly off when actually using the map. I

Higgy: Maybe the above described issue is your problem as well?


RalfZ
Munich, Germany





More information about the talk mailing list