26
26
QgsProcessingParameterRasterLayer ,
27
27
QgsProcessingParameterBand ,
28
28
QgsProcessingParameterBoolean ,
29
- QgsProcessingParameterFileDestination
29
+ QgsProcessingParameterFileDestination ,
30
+ QgsProcessingParameterNumber
30
31
)
31
32
from processing .algs .gdal .GdalAlgorithm import GdalAlgorithm
32
33
from processing .algs .gdal .GdalUtils import GdalUtils
36
37
class gdal2xyz (GdalAlgorithm ):
37
38
INPUT = 'INPUT'
38
39
BAND = 'BAND'
40
+ SRCNODATA = 'NODATA_INPUT'
41
+ DSTNODATA = 'NODATA_OUTPUT'
42
+ SKIPNODATA = 'SKIP_NODATA'
39
43
CSV = 'CSV'
40
44
OUTPUT = 'OUTPUT'
41
45
@@ -49,6 +53,16 @@ def initAlgorithm(self, config=None):
49
53
self .tr ('Band number' ),
50
54
1 ,
51
55
parentLayerParameterName = self .INPUT ))
56
+
57
+ self .addParameter (QgsProcessingParameterNumber (self .SRCNODATA ,
58
+ self .tr ('Input pixel value to treat as "nodata"' ),
59
+ optional = True )) # GDAL > 3.6.3
60
+ self .addParameter (QgsProcessingParameterNumber (self .DSTNODATA ,
61
+ self .tr ('Assign specified "nodata" value to output' ),
62
+ optional = True )) # GDAL > 3.6.3
63
+ self .addParameter (QgsProcessingParameterBoolean (self .SKIPNODATA ,
64
+ self .tr ('Do not output nodata values' ),
65
+ defaultValue = False )) # GDAL > 3.3
52
66
self .addParameter (QgsProcessingParameterBoolean (self .CSV ,
53
67
self .tr ('Output comma-separated values' ),
54
68
defaultValue = False ))
@@ -79,6 +93,30 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
79
93
'-band' ,
80
94
str (self .parameterAsInt (parameters , self .BAND , context ))
81
95
]
96
+
97
+ if self .SRCNODATA in parameters and parameters [self .SRCNODATA ] is not None :
98
+ if GdalUtils .version () > 3060300 : # src/dstnodata broken <= 3.6.3 https://github.com/OSGeo/gdal/issues/7410
99
+ srcnodata = self .parameterAsDouble (parameters , self .SRCNODATA , context )
100
+ arguments .append ('-srcnodata' )
101
+ arguments .append (srcnodata )
102
+ else :
103
+ raise QgsProcessingException (self .tr ('The source nodata option (-srcnodata) is only available on GDAL 3.6.4 or later' ))
104
+
105
+ if self .DSTNODATA in parameters and parameters [self .DSTNODATA ] is not None :
106
+ if GdalUtils .version () > 3060300 : # src/dstnodata broken <= 3.6.3 https://github.com/OSGeo/gdal/issues/7410
107
+ dstnodata = self .parameterAsDouble (parameters , self .DSTNODATA , context )
108
+ arguments .append ('-dstnodata' )
109
+ arguments .append (dstnodata )
110
+ else :
111
+ raise QgsProcessingException (self .tr ('The destination nodata option (-dstnodata) is only available on GDAL 3.6.4 or later' ))
112
+
113
+ if self .SKIPNODATA in parameters :
114
+ if GdalUtils .version () >= 3030000 : # skipnodata added at GDAL 3.3
115
+ if self .parameterAsBoolean (parameters , self .SKIPNODATA , context ):
116
+ arguments .append ('-skipnodata' )
117
+ else :
118
+ raise QgsProcessingException (self .tr ('The skip nodata option (-skipnodata) is only available on GDAL 3.3 or later' ))
119
+
82
120
if self .parameterAsBoolean (parameters , self .CSV , context ):
83
121
arguments .append ('-csv' )
84
122
0 commit comments