I have this code I use in the QGIS Python console. I used it a few days ago and it worked, but I tried using it again and I got this error:
Traceback (most recent call last):
File "C:\PROGRA~1\QGIS3~1.10\apps\Python37\lib\code.py", line 90,
in runcode exec(code, self.locals) File "<input>", line 1,
in <module> File "<string>", line 33,
in <module> File "C:/PROGRA~1/QGIS3~1.10/apps/qgis-ltr/./python/plugins\processing\tools\general.py", line 136,
in runAndLoadResults for param in alg.parameterDefinitions():
AttributeError: 'NoneType' object has no attribute 'parameterDefinitions'
I checked all my definitions, and I see they are correct. How can I possibly resolve this?
# Import necessary modules
from qgis.core import QgsApplication, QgsRasterLayer
import processing
# Initialize QGIS application
QgsApplication.setPrefixPath("/path/to/qgis", True)
QgsApplication.initQgis()
# Set path to input raster layer
file_dir = 'D:/WDF_03012023'
mask_dir = 'D:/WDF_03012023/masks'
Date = '030123' #to always edit depending on Date involved
Ring_num = '1aRuta' #always change this to what is after the R in the file name
# Construct the Ring-specific names and paths
Ring_name = f'030123_R{Ring_num}' #always change date here to the date working on
mask_name = f'mask_{Ring_name[7:]}_{Date}'
Ring = file_dir + '/' + Ring_name + '.tif'
mask = mask_dir + '/' + mask_name + '.tif'
# Load the input raster layer
raster_layer = QgsRasterLayer(mask)
# Polygonize the raster layer
polygonized_layer = processing.runAndLoadResults(
"gdal:polygonize",
{
'INPUT': raster_layer,
'BAND': 1,
'FIELD': 'DN',
'EIGHT_CONNECTEDNESS': False,
'EXTRA': '',
'OUTPUT': 'TEMPORARY_OUTPUT' # Let QGIS use the specified temporary directory
}
)
# Fix geometries of the polygonized layer
fixed_geometries = processing.runAndLoadResults("native:fixgeometries", {'INPUT': polygonized_layer['OUTPUT'], 'OUTPUT': 'TEMPORARY_OUTPUT'})
# Clip the input raster based on the mask
clipped_ring = processing.runAndLoadResults(
"gdal:cliprasterbymasklayer",
{
'INPUT': Ring,
'MASK': fixed_geometries['OUTPUT'],
'SOURCE_CRS': None,
'TARGET_CRS': None,
'NODATA': None,
'ALPHA_BAND': False,
'CROP_TO_CUTLINE': True,
'KEEP_RESOLUTION': True,
'SET_RESOLUTION': False,
'X_RESOLUTION': None,
'Y_RESOLUTION': None,
'MULTITHREADING': False,
'OPTIONS': '',
'DATA_TYPE': 0,
'EXTRA': '',
'OUTPUT': 'TEMPORARY_OUTPUT'
}
)
parameterDefinitions
in your code so it must be a problem from something called by it, which should be revealed by the full traceback error...