2

When using PyQgis for QGIS 3.4 is it possible to add a new WMS/WMTS Server to the Data Source Manager?

If yes and once created, is it then possible to add a new WMS layer to the map using the new connection within a Python plugin?

I have been trying to add a layer using authentication but my server needs to pre-authenticate so that is not working and in any case the only way it works using the normal GUI is to select the two ignore GetCapabilities options in the Data Source Manager anyway so it is unlikely it would work via QgsRasterLayer anyway.

1

Whilst I have not yet discovered how to add full server connections I did discover that my issue when trying to add layers individually was because I needed QGIS to ignore the capabilities when constructing URLs.

This is most likely fairly specific to our own server configuration but it might be useful to others to know how to set the two options in the "Create a New WMS/WMTS Connection" dialog via pyqgis.

It turns out they can be added directly as parameters (see QGIS Documentation).

The options you need are:

  • IgnoreGetFeatureInfoUrl
  • IgnoreGetMapUrl

In the format described in the linked documentation page these would be set as follows:

quri.setParam("IgnoreGetFeatureInfoUrl", '1') quri.setParam("IgnoreGetMapUrl", '1')

Using these settings it was possible to add the layers individually as QgsRasterLayer layers.

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.