What is dpiMode in a WMS URI and what do the different settings mean?

I use a WMS layer as a basemap in a QGIS project. Its URI includes dpiMode=7. There are some visual artifacts when my overall map is rendered at 96 dpi (for MBTiles generation), not explained by CRS reprojection issues. My hypothesis is that the WMS server is dutifully rendering images at a dpi that doesn't scale well to 96.

I've tried changing dpiMode to 6 and 8, which changes on-screen label size, consistent with my hypothesis (and QGIS kindly rescaling). But I haven't been able to find a specification online that would explain what dpiMode does and what the settings mean. In particular, what dpiMode will serve up images that render the best at an eventual 96 dpi.

enter image description here

There are lots of search hits for WMS "dpiMode", but they're generally other peoples' WMS URIs which all just set dpiMode=7, which seems to be a default.

  • It's not part of the WMS specification. It's a vendor specific parameter. It may be added to the request by QGIS, but if the server doesn't support it, it will make no difference to the response. – nmtoken Jan 31 at 8:15
  • 1
    this code: qgis.org/api/qgsnewhttpconnection_8cpp_source.html makes me think that dpiMode is just an internal QGIS parameter (not sure why it appears in the URL at all), that is used to set the DPI parameter (also non WMS standard), used in the request. Perhaps you could check by changing the type of WMS server option, and looking at URLs sent. – nmtoken Jan 31 at 11:45

DPIMode means nothing to a vanilla WMS server - it (and variants) is an extension adopted by some WMS servers to allow users to hint to the server that it intends to use a display method which is a long way from the "standard" 96dpi (usually a printer with values of 300 or 600 dpi). This allows the server to make the labels, line widths and other style elements rendered in pixels bigger so they look the "right" size when printed (see for example this question).

I'm unable to find a definitive definition of dpiMode=7 but it looks like it is a QGis thing and probably points to a predefined set of formatting options.

| improve this answer | |

Well, I've returned to this and come up with the following (apparent) answer, by watching the actual network requests sent out by QGIS using the QGIS Network Logger plug-in

dpiMode appears to be an internal set of flags used by the WMS provider to decide how to specify desired DPI to the WMS server in the http request. The actual DPI requested is the one in the map canvas or layout being rendered. And (as per the other comments/answers) it is then up to the server how it responds to the request.

Different dpiMode settings therefore may result in different renderings depending on whether the specific server "gets the message" regarding QGIS's target DPI or not, but (unfortunately for me) this is not a method to systematically and reliably scale WMS renderings, and in particular their text size, up and down.

  • dpiMode & 4 > 0 means a FORMAT_OPTIONS=dpi:xxx is appended to the WMS request.
  • dpiMode & 2 > 0 means MAP_RESOLUTION=xxx
  • dpiMode & 1 > 0 means DPI=xxx

So dpiMode=7 means all 3 ways of trying to give the server the target DPI are used. If dpiMode=6 as in my question, &DPI=xxx is skipped in the WMS request, etc. In my case, the server's default DPI seems to be 90 (but this may vary, I suspect), my screen map canvas DPI is 120, and my layout DPI is 96, which of course causes erratic behaviour if you incorrectly assume dpiMode is a scaling factor.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.