我正在使用 Python 代码打开 QGIS 项目。这个想法是对过去使用的文件进行清单。一些源文件已在网络上重新定位。当您打开一个项目时,您会看到一个处理不可用图层的屏幕。当您使用 Python 打开项目时,有什么方法可以避免出现该屏幕吗?
我发现有这样的类:https ://qgis.org/pyqgis/3.8/core/QgsProjectBadLayerHandler.html?highlight=handlebadlayers
到目前为止我的代码
from qgis.core import QgsProject
project = QgsProject.instance()
for dir in scan:
rootdir = dir
for subdir, dirs, files in os.walk(rootdir):
for file in files:
if(file[-3:] == 'qgz'):
path = os.path.join(subdir, file)
if project.read(path):
pass
else:
print(f'Couldn\'t open {path}')