I wrote a QGIS plugin and at the moment I'm going through the error messages. I'm stuck on the following:
Now I show you the top of my code where I import everything and the function containing the gdal algorithm:
from qgis.PyQt.QtCore import QSettings, QTranslator, QCoreApplication
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtWidgets import QAction, QFileDialog
from qgis.core import *
from osgeo import gdal
from processing.core.Processing import Processing
import glob, os.path
from .resources import *
from .Clip_XYZ_dialog import ClipXYZDialog
def clipRasters(self):
Processing.initialize()
inputDir = self.getInputPath()
outputDir = self.getOutputPath()
for lyr in glob.glob(os.path.join(inputDir, "*xyz")):
processing.run("gdalogr:cliprasterbymasklayer", {lyr, self.getVectorLayer(), 'none', True, False, 0,
outputDir + lyr})
Interesting is that "from osgeo import gdal" is actually grayed out in my code and processing has a red underline that marks some sort of error. It says "unresolved reference 'processing'" but I don't know what that means. Can someone explain me the error and what should be done?
import processing
after the linefrom osgeo import gdal
.gdal:cliprasterbymasklayer
(remove theogr
). Also, you shouldn't needfrom osgeo import gdal
since you're calling the processing module which would contain the algorithm instead, unless you're usinggdal
directly later in your plugin.Processing.initialize()
outside of the function as it only needs to be executed once.