I'm interesting in generating URL's to get a single map PNG for a given latitude/longitude range. Experimenting with the "Export" tab at openstreetmap.org, I've found that you must pass the latitude/longitude range, as well as a scale value. I haven't been able to figure out exactly how to calculate the scale that gives me the number of pixels I want.
I working from the information here: http://wiki.openstreetmap.org/wiki/FAQ#What_is_the_map_scale_for_a_particular_zoom_level_of_the_map.3F
It appears that scale means the ratio of the map size shown on the screen, assuming a DPI of 72, to the actual size of the geographic area included. The page indicates that that is only true at the equator, however, and the scale number is interpreted differently at other latitudes, but let's skip that for now and look at the equator.
A single degree of longitude at the equator is 111320.0 meters across. As a silly example to keep the math simple, if I use the export web page interface to set the rectangle to a 1 degree square centered on the equator, and the scale to 1:1, it reports an image size of 397569610 pixels wide (don't worry I didn't try to download this image!). Assuming 72dpi, and with 39.37 inches in a meter, that works out to 397569610 / (72*39.37) = 140,254 meters, rather than the expected 111,320. (It's not just an artifact of using that absurd scale, it works out the same at other scales with another multiplication step).
Any idea of what's wrong with my assumptions/math?
asked 14 Dec '11, 00:07
Well your math seems sane and I don't really have an answer on that part... but if you are looking to get static map images, another good place to look is the MapQuest Open API. They have a static map function that serves up OSM data but also has all kinds of bells and whistles. Their blog post about it with a link to the documentation can be found here:
answered 14 Dec '11, 05:11
My suspicion is that something is wrong because you even start to wonder. Pixels and real world units don't go well together and the whole concept of "map scale" is worth little when every medium has a different resolution. For the sake of argument, let's just say our web interface assumes 90 dpi and not 72, then your computation works out fine!
answered 14 Dec '11, 00:36
Frederik Ramm ♦
To calculate it, use these formulas:
The resolution means how many meters per pixel you get.
The scale means, how many cm in reality is 1 cm on the paper (or on the screen).
So if you have a screen with 96 dpi, you get that one pixel is 1.1943 meters. And you get a scale of 1 : 4 231 which means that 1 cm on your screen is 42.3 m in reality.
If you have a printer which prints 300 dpi … (now do the calculations yourself).
There is a wiki page about scaling.
answered 14 Feb '14, 11:55