3

I am trying to add a WMTS raster layer in QGIS 3.8 using Python (for my plugin).

I have found this Loading Layers - Raster in the documentation, but I cannot make it work.

I tried this:

QgsRasterLayer(f'url={url}&crs=EPSG:4326&format=image/png&tileMatrixSet=4326&username={name}&password={pwd}', 'some layer name', 'wmts').isValid()

But it returns False.

I see the same question asked a lot on this site, but no answer solves my problem.

How can I deal with this?

The URL works fine when I add the layer through the UI.

Other post : Loading a WMS layer to QGIS using python

  • 1
    should it not be f'url={url}?crs... or if url has a ? just f'url={url}crs... as per syntax key[=value]& – nmtoken Oct 24 '19 at 16:47
  • Welcome to GIS SE! We're a little different from other sites; this isn't a discussion forum but a Q&A site. Please check out our short [tour] to learn about our focussed Q&A format. If you have seen this question asked previously on this site then please provide links to those questions so that potential answerers do not have to retrace your steps. – PolyGeo Oct 24 '19 at 22:39
  • @nmtoken : unfortunaltly he question mark doesn't change the result. – Raphael Bahuau Oct 25 '19 at 07:26
  • @PolyGeo : Sure I edit the principal post. – Raphael Bahuau Oct 25 '19 at 07:28
  • Those previous questions all seem to be about WMS and you appear to be asking about WMTS. In any event most if not all of them look like they should be reviewed to see which are duplicates. – PolyGeo Oct 25 '19 at 08:15
  • Yes it's for WMS, but I thought it would be similar. I don't find any other post with a solution for me. Loading raster layer using PyQGIS? is to load from disk, I want to load from url. Projection issue with WMTS in QGIS? said Qgis had some issue with wmts, but as I said, it function properly when I add the layer trought UI (I think the post is outdated and it sould be fixed in QGis 3 now) – Raphael Bahuau Oct 25 '19 at 08:27

0 Answers0