[GIS] Relationship between scale, ppi, and map resolution

openlayers-2resolutionscale

Wanting to know the screen resolution (pixels per inch) of my device, I displayed my map resolution and scale using this openlayers code:

console.log("resolution: " + map.getResolution());
console.log("scale: " +map.getScale());

which gave the result below:

"resolution: 611.4962261962891" mapTest.html:119
"scale: 1733376.0653978775"

Then I used this formula (from https://msdn.microsoft.com/en-us/library/aa940990.aspx):

Map scale = 1 : (ScreenRes pixels/inch * 39.37 inches/meter *
156543.04 meters/pixel * cos(latitude) / (2 ^ zoomlevel))

With my values:

1733376.065 = (ScreenRes ppi * 39.37 inches/meter * 611.496 meters/pixel * cos(51.02)) / (2^8)

The latitude I used is 51.20. But the formula produced 28889.6. I think this is pixels per meter so I divided by 39.37 to get pixels per inch. But that resulted in 733.797 which is an unrealistic pixels per inch. I was expecting value between 72 to 96.

What is going on here? Did I do something wrong or is the formula is wrong? The image is an OpenStreetMap image and the projection used is 900913. I hope some one can help.

Best Answer

You have indeed made some errors in your calculation. 156543.04 meters/pixel is a constant "based on the diameter of the Earth and the equations Microsoft used to set the zoom levels" used in two equations on the page you reference - it's not a variable. Your mistake was in substituting the map resolution your openlayers code returned for the constant. The first equation is:

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

In theory, according to the table provided at the page you linked, this would be 611.5 m/p at zoom level 8, at the equator. That's almost exactly the number you were given by your openlayers code, but if you solve that equation at 51.02 lat it comes out to be closer to 384.7 m/p. That matches up with the sentence under their chart, which gives an example (at a different zoom level) for a lat other than the equator. However it is a bit odd that your openlayers code is returning 611.5 for zoom level 8 at 51.02 and not 384.7. That suggests to me that the equation may not hold for openlayers [actually it looks like very similar numbers in the openlayers docs] - the page you link to is specific to Bing maps and as noted above is based on their equations to set zoom levels. Or it may just be that code returns the at-the-equator value, regardless of where you're actually looking, while the displayed scalebar takes the lat into account.

The formula you actually want to solve (theoretically, with your values) should be:

1733376.065 = [(ScreenRes ppi * 39.37 inches/meter * 156543.04 meters/pixel * cos(51.02)) / (2^8)]

Now, as I mentioned in my comment, your true screen resolution in terms of ppi is hardware/device dependent and varies from display to display. If you want to find it, it may be a published specification or you may have to calculate it. You first need the native 'resolution' of the display. This would be more properly termed pixel dimensions, because resolution is actually the density of pixels (ppi) - but we use resolution interchangeably.

So let's say 1920x1080, a standard HD display (and note this needs to be the native number, NOT what it's being run at). Since we need the diagonal pixel dimension, simple a^2 + b^2 = c^2 gives us 2202.9 diagonal pixels. Now we need the actual diagonal dimension of the display. For instance a 24" display may only be 23.8" - this is pretty much always in the specs (usually as 'viewable' or some similar adjective). Diagonal pixels divided by diagonal inches gives us 92.6 ppi. Were it a 27" display at the same resolution, it would be 81.6 ppi. A 5" gives 440.6 ppi. I found a handy calculator on the web that can do this math for you if you have the right numbers.

This will give you a much more accurate (possibly even correct) result than trying to use the Microsoft equation and should be easier. The relationship, per your question title, is somewhat complex - we're talking about scaled scales essentially. And if you run a resolution (or rather pixel dimension) different than native, it gets even more complicated.

Go back to what scale is - unit x on map representing unit y in the real world. In computers there is no scale relative to anything but pixels. That's the first equation, what they term map resolution. Say 100 pixels represents 600m. On a phone display those 100 pixels may only be 0.25 inch, while on a 30" computer monitor they might be 1 inch - but they still both represent 600m. That's why the page has the second equation - because most people don't think of map scale in terms of pixels, they want a inch : mile ratio (or whatever units). The problem is that ratio changes depending on what display you're looking at while the pixel : real world unit ratio doesn't, assuming the same pixel dimensions and zoom on the image.

Related Question