2

I have try a lot of PyQGIS lines codes to try to add any layer in WMTS from Geoservices using Python console in QGIS 3.34.

Geoservice site: https://geoservices.ign.fr/services-web-experts-ortho

Layer to add: BD ORTHO® 20 cm HR.ORTHOIMAGERY.ORTHOPHOTOS

URL: https://wxs.ign.fr/ortho/geoportail/wmts?SERVICE=WMTS&VERSION=1.0.0&REQUEST=GetCapabilities

I have try:

qgis.utils.iface.addRasterLayer(
    "tileMatrixSet=EPSG:3857&crs=EPSG:3857&layers=brtachtergrondkaart&styles=&format=image/jpeg&url=https://wxs.ign.fr/ortho/geoportail/wmts/HR.ORTHOIMAGERY.ORTHOPHOTOS", # uri
    "wmts master example",
    "wms"
)

But it is creating a corrupted layer.

1 Answer 1

4

A good way to know what url to use in the QgisInterface.addRasterLayer() function is to manually add the layer to the legend and directly copy its source.

Here you can create a WMS/WMTS connection using your url:

https://wxs.ign.fr/ortho/geoportail/wmts?SERVICE=WMTS&VERSION=1.0.0&REQUEST=GetCapabilities

And then load the "Ortho 20 cm" raster layer.

Finally you can access the Layer Properties of the layer and in the Information tab you can copy the source value. This is the url to use in the addRasterLayer() function:

crs=EPSG:3857&dpiMode=7&format=image/jpeg&layers=HR.ORTHOIMAGERY.ORTHOPHOTOS&styles=normal&tileMatrixSet=PM&url=https://wxs.ign.fr/ortho/geoportail/wmts?SERVICE%3DWMTS%26VERSION%3D1.0.0%26REQUEST%3DGetCapabilities

The following code will load the right raster layer directly:

iface.addRasterLayer(
    "crs=EPSG:3857&dpiMode=7&format=image/jpeg&layers=HR.ORTHOIMAGERY.ORTHOPHOTOS&styles=normal&tileMatrixSet=PM&url=https://wxs.ign.fr/ortho/geoportail/wmts?SERVICE%3DWMTS%26VERSION%3D1.0.0%26REQUEST%3DGetCapabilities", # uri
    "wmts master example",
    "wms"
)

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.