The following code gives an "invalid" layer.
urlWithParams = 'type=xyz&url=https://tile.openstreetmap.org/%7Bz%7D/%7Bx%7D/%7By%7D.png&zmax=19&zmin=0'
raster_layer = QgsRasterLayer(urlWithParams, 'OpenStreetMap', 'wms')
print(raster_layer.isValid()) # False
I guess it can be invalid for many different reasons:
- online resource is currently not available
- data is corrupted
- URL is invalid
- authentication is required but not provided
- authentication was rejected by server
- etc.
I want to ask overall:
- How can I get information about why a layer is invalid?
- Is there a log that I should read?
- Or is it possible to get more information interactively through Python, maybe with a kind of error code that my plugin can act on and then give relevant feedback to the plugin user
Motivation for asking this:
I am trying to add a raster layer with Open Street Maps in pyqgis in a standalone script, but the layer is invalid (QgsRasterLayer is invalid when run as standalone PyQGIS).
Trueand a valid OSM WMS layer when I changedprint(raster_layer.isValid())– Taras Jun 07 '22 at 06:06