NOTICE: is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

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, 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:

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

Jesse2's gravatar image

accept rate: 0%

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:

permanent link

answered 14 Dec '11, 05:11

ToeBee's gravatar image

accept rate: 27%

Thanks for the info, I hadn't seen that, I'll check out their API/terms!

(16 Dec '11, 00:23) Jesse2

They are in general pretty liberal with their terms, especially for the "open" stuff. A general page about their open products can be found here:

(16 Dec '11, 07:21) ToeBee

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!

permanent link

answered 14 Dec '11, 00:36

Frederik%20Ramm's gravatar image

Frederik Ramm ♦
accept rate: 23%

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?

(16 Dec '11, 00:17) Jesse2

To calculate it, use these formulas:

resolution = 156543.034 meters/pixel * cos(latitude) / (2 ^ zoomlevel)

The resolution means how many meters per pixel you get.

scale = 1 : (dpi * 39.37 in/m * resolution)

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.

permanent link

answered 14 Feb '14, 11:55

erik's gravatar image

accept rate: 9%

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 14 Dec '11, 00:07

question was seen: 15,223 times

last updated: 14 Feb '14, 11:55

NOTICE: is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum