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.

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).

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:

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!

Thanks for the response, the math works out well at 90 dpi! I'm now able to generate a scale value that generates ~1 megapixel maps for a given lat/lon range. But, maybe I'm thinking about this wrong - is there a better way to specify desired image size, other than through scale?