[QGIS-Developer] QGIS standalone script examples (and Oracle)

Richard Duivenvoorde rdmailings at duif.net
Wed Jun 2 00:02:12 PDT 2021


On 6/1/21 6:48 PM, Paul Wittle wrote:
> Thanks,
> 
> I might have a look but to be honest there seem to be quite a few ways things can fail.
> 
> I have now switched to a template that uses WFS / WMS layers only and they all load accept for a WFS layer using an authentication manager password; others using tokens are fine.
> 
> I've checked that the authentication manager is now opening early enough and contains the relevant authcfg ID, which it does, but still it loses the source for that layer as well.
> 
> Is there a way to load a project in QGIS and return a list of invalid layers?
> 
> I'm assuming that what is happening is that it is loading the project but because it is in Python there is no 'handle bad layers' dialogue as there is in the main GUI.
> 
> It would be helpful if that function was available so I could do something like this:
> 
> Read Project
>     = list of bad layers
> Check list, if greater than 0 then handle bad layers
> Do stuff
> Save project

I think you can use this in your script?

layers = QgsProject.instance().mapLayers()
# layers is dict name:layer
for name in layers:
  print(f'Layer "{name}" isValid = {layers[name].isValid()}')

see https://qgis.org/pyqgis/master/core/QgsMapLayer.html?#qgis.core.QgsMapLayer.isValid

Another option: maybe you can install nightly builds of QGIS on windows:
https://qgis.org/en/site/forusers/alldownloads.html#id6
and then use the 'DebugView' log viewer to see the messages others see on linux
(see http://osgeo-org.1560.x6.nabble.com/How-to-see-log-debug-messages-in-Osgeo4W-installer-qgis-dev-td5047542.html but no need to install via osgeo4w anymore as we have a nightly now with debug info)

Regards,

Richard


More information about the QGIS-Developer mailing list