1

In OpenLayers v5, if I have a view defined like this:

var view = new View({
    center: [952014.59, 5571269.68],
    zoom: 8
});

, trying to get its resolution doing view.getResolution() outputs 611.49622628141.

How should I interpret this number?

Here is my problem: I am trying to figure out if the resolution of the view is greater/smaller than that found parsing the MaxScaleDenominator and MinScaleDenominator of this WMS. They are 500000 and 0 respectively for each layer.

However, the numbers from OL and the WMS seem to be in different units, and frankly I understand the ones coming from the WMS but not those coming from OL.

Can anybody help me understanding how should I handle this, in order to make these numbers comparable?

EDIT1

The main problem is that view.getResolution() seems to output values which are always the same regardless of the latitude.

Consider my output: 611.49622628141.

If you look at the equation presented at this link, the pixel scale (Spx) can be obtained by:

Spx = C * cos(latitude) / 2 ^ (zoomlevel + 8)

, where C is the equatorial circumference of the Earth (equal to 40075016.686 m). My zoomlevel is 8 and the latitude assumed by OL seems always 0 (equator). Indeed, if you do the calculations, you'll obtain eaxctly 611.49622628141.

So I guess that I should not trust the output from view.getResolution() to make my comparison, am I wrong? If I am not, this would be a good reason not to close this question, as it has very much to do with this specific method.

EDIT2

By the way, as far as I understand, following the answer in the duplicated question linked (making adjustment as per last comment (cm to m missing conversion), I am finally able to calculate the scale I needed from the view.getResolution() output, but the doubts I had (see EDIT1) still remain unsoved.

My calculation led me to:

map scale = 
    pixel resolution (as per view.getResolution()) / screen distance per pixel (in meters) =
  611,49622628141 /   0,00028 =
    2183915

, so approximately 1:2 millions.

My doubt if .getResolution() output is accurate for any projection/latitude/(map size?) still is there...

marked as duplicate by JGH, LaughU, Jochen Schwarze, Andre Silva, whyzar Nov 19 '18 at 13:56

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    The unit is "projection unit per pixel", likely meters/pixel in your case. – JGH Nov 19 '18 at 1:49
  • @JGH I surely want to solve this accurately, but for a quick and dirt workaround, what if I use the conversion "m / pixel" to "Scale" presented here: wiki.openstreetmap.org/wiki/Zoom_levels. Would it be reasonable in your opinion? – umbe1987 Nov 19 '18 at 11:55
  • 1
    It depends on the projection you are using. If you use WebMercator, it is valid at the equator only. At 44 degrees of latitude, the distortion (vs at the equator) is more than 40% – JGH Nov 19 '18 at 12:08
  • Thanks for clarifying. Will try to find out a precise way although reading the linked answer is still a bit of a headache for my simple non-mathematical mind. – umbe1987 Nov 19 '18 at 12:09
  • Anyway, don't know if OL makes any assumption on the projection and latitude, but if I use the exact equation found in the aforementioned link (in my firts comment), I obtain the exact value I see from view.getResolution(). The equation is "Spixel = C * cos(latitude) / 2^(zoomlevel + 8)". Given the assumption that latitude is zero (equator), "C" is the "equatorial circumference of the Earth" and my zoomlevel is 8, I obtain exactly 611.49622628141. – umbe1987 Nov 19 '18 at 12:15