2

I am coding a python plugin to QGIS that connects to the UK National Biodiversity Network (NBN) Web Mapping Service (WMS). In general, I don't have any problems doing this with the QgsRasterLayer API when I want to access the WMS as a public user. The problem is when I want to access the WMS as a registered user (to get access to secured data).

The NBN WMS provides a method for doing this by supplying a username and an MD5 hashed password as additional parameters to the web service called username and userkey respectively (https://data.nbn.org.uk/Documentation/Web_Services/Web_Map_Services/).

The parameters work as advertised when requests are tested in a browser. However, they have no effect when used through QGIS and when I used Fiddler to examine the HTTP requests that QGIS is actually sending to the NBN WMS, I find that the username and userkey parameters are no sent by QGIS.

They are non-standard parameters, but the OGC standard says that non-standard parameters are allowed (and don't break the standard). Does anyone know why QGIS strips these non-standard parameters out of the HTTP request or how I can get around it?

2 Answers 2

4

As a workaround you can include extra parameters into the WMS server base URL. Remember also to check the "Ignore GetMap URI reported in capabilities". If username and userkey are changed you must edit the WMS connection details accordingly. Standard does not say either that WMS clients should keep the vendor parameters. Make a feature request for QGIS and suggest that there should be a box for vendor parameters. Ask to make it large so that also SLD_BODY fits into the box. Check first if such feature request exists already.

2
  • Thanks for your suggestion for a workaround. I've only just seen it (after a solution was suggested) - otherwise I would have given it a go. Cheers. Commented Nov 27, 2014 at 11:24
  • FYI, this has been raised as feature request in 2015: hub.qgis.org/issues/12255 but closed with the same work around as described here...
    – Dave
    Commented Dec 23, 2016 at 15:09
3

I believe that the url you provide to the QgsRasterLayer needs to be url encoded.

Otherwise it seems that the url parameter which you pass to the QgsRasterLayer splits upon the '&' character.

The following snippet demonstrates the creation of a QgsRasterlayer for Cochlearia danica L.

wmsService = 'https://gis.nbn.org.uk/SingleSpecies/NBNSYS0000002854?username=NBN_USER&userkey=PASS_KEY&'

url = 'url=' + urllib.quote_plus(wmsService) # encode the url
layer = QgsRasterLayer(url, 'NBN WMS layer', 'wms')

I have tested this in QGis 2.4

1
  • Thanks Chris - that solved the problem! I don't know why I didn't think to try this. Thanks to your help, I've been able to publish a new release with user-level access enabled. Commented Nov 27, 2014 at 11:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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