Bug report #17282

Legend image for root group of WMS service

Added by dr - 11 months ago. Updated 10 months ago.

Category:Web Services clients/WMS
Affected QGIS version:2.18.13 Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:
Crashes QGIS or corrupts data:No


If open root group of WMS service then legend image only for one layer will be displayed at table of contents.

wms_tree.png (11.7 KB) dr -, 2017-10-15 04:17 PM


#1 Updated by Giovanni Manghi 11 months ago

  • Affected QGIS version changed from master to 2.18.13

#2 Updated by Richard Duivenvoorde 10 months ago

I had a look into this, and the crux is that selecting the 'root' of the layer tree is interpreted by QGIS as requesting the layer width the 'default' style (that is: in the url you send you get an empty 'style' parameter: ...&STYLES=&LAYERS=...

BUT according to the OGC WMS spec:
"If only a single style is available, that style is known as the “default” style"...
"If the server advertises several styles for a layer, and the client sends a request for the default style, the choice of
which style to use as default is at the discretion of the server. The ordering of styles in the service metadata does
not indicate which is the default."

And caveat: from the capabilities document of a WMS you can not make up WHAT the default style is in case there are more styles available. Another problem: there could be more styles available then advertized, as the style is actually cascading...

So in the code of QGIS
see: https://github.com/qgis/QGIS/blob/master/src/providers/wms/qgswmsprovider.cpp#L285
you only get a valid legend url when:
1) there is just ONE style available (of which QGIS then rightfully concludes that THAT is the default style)
2) you request one of the named styles
3) (QGIS special): if you name one of the styles as 'default'

So in this case we cannot do anything (I think). Picking the first style for the legend in case of more style could be wrong (as it is not defined as the default style). So I think QGIS does what it can do.

IF you are managing the WMS yourself, you could name the style 'default', but you get into trouble off course when you have more several layers for which you want do define different 'defaults'.

IF there would be a OGC WMS 1.3.1 it would be nice if one of the styles would be advertised as 'default'.

#3 Updated by Giovanni Manghi 10 months ago

  • Status changed from Open to Feedback

Also available in: Atom PDF