39
39
QgsProcessingParameterBoolean ,
40
40
QgsProcessingParameterRasterDestination ,
41
41
QgsProcessingParameterCrs ,
42
+ QgsProcessingParameterString ,
42
43
QgsProcessingOutputLayerDefinition ,
43
44
QgsProcessingUtils )
44
45
from processing .algs .gdal .GdalAlgorithm import GdalAlgorithm
@@ -57,6 +58,7 @@ class buildvrt(GdalAlgorithm):
57
58
ADD_ALPHA = 'ADD_ALPHA'
58
59
ASSIGN_CRS = 'ASSIGN_CRS'
59
60
RESAMPLING = 'RESAMPLING'
61
+ SRC_NODATA = 'SRC_NODATA'
60
62
61
63
RESOLUTION_OPTIONS = ['average' , 'highest' , 'lowest' ]
62
64
RESAMPLING_OPTIONS = ['nearest' , 'bilinear' , 'cubic' , 'cubicspline' , 'lanczos' , 'average' , 'mode' ]
@@ -82,38 +84,45 @@ def defaultFileExtension(self):
82
84
return 'vrt'
83
85
84
86
self .addParameter (QgsProcessingParameterMultipleLayers (self .INPUT ,
85
- QCoreApplication . translate ( "ParameterVrtDestination" , 'Input layers' ),
87
+ self . tr ( 'Input layers' ),
86
88
QgsProcessing .TypeRaster ))
87
89
self .addParameter (QgsProcessingParameterEnum (self .RESOLUTION ,
88
- QCoreApplication . translate ( "ParameterVrtDestination" , 'Resolution' ),
90
+ self . tr ( 'Resolution' ),
89
91
options = self .RESOLUTION_OPTIONS ,
90
92
defaultValue = 0 ))
91
93
self .addParameter (QgsProcessingParameterBoolean (self .SEPARATE ,
92
- QCoreApplication . translate ( "ParameterVrtDestination" , 'Place each input file into a separate band' ),
94
+ self . tr ( 'Place each input file into a separate band' ),
93
95
defaultValue = True ))
94
96
self .addParameter (QgsProcessingParameterBoolean (self .PROJ_DIFFERENCE ,
95
- QCoreApplication . translate ( "ParameterVrtDestination" , 'Allow projection difference' ),
97
+ self . tr ( 'Allow projection difference' ),
96
98
defaultValue = False ))
97
99
98
100
add_alpha_param = QgsProcessingParameterBoolean (self .ADD_ALPHA ,
99
- QCoreApplication . translate ( "ParameterVrtDestination" , 'Add alpha mask band to VRT when source raster has none' ),
101
+ self . tr ( 'Add alpha mask band to VRT when source raster has none' ),
100
102
defaultValue = False )
101
103
add_alpha_param .setFlags (add_alpha_param .flags () | QgsProcessingParameterDefinition .FlagAdvanced )
102
104
self .addParameter (add_alpha_param )
103
105
104
106
assign_crs = QgsProcessingParameterCrs (self .ASSIGN_CRS ,
105
- QCoreApplication . translate ( "ParameterVrtDestination" , 'Override projection for the output file' ),
107
+ self . tr ( 'Override projection for the output file' ),
106
108
defaultValue = None , optional = True )
107
109
assign_crs .setFlags (assign_crs .flags () | QgsProcessingParameterDefinition .FlagAdvanced )
108
110
self .addParameter (assign_crs )
109
111
110
112
resampling = QgsProcessingParameterEnum (self .RESAMPLING ,
111
- QCoreApplication . translate ( "ParameterVrtDestination" , 'Resampling algorithm' ),
113
+ self . tr ( 'Resampling algorithm' ),
112
114
options = self .RESAMPLING_OPTIONS ,
113
115
defaultValue = 0 )
114
116
resampling .setFlags (resampling .flags () | QgsProcessingParameterDefinition .FlagAdvanced )
115
117
self .addParameter (resampling )
116
118
119
+ src_nodata_param = QgsProcessingParameterString (self .SRC_NODATA ,
120
+ self .tr ('Nodata value(s) for input bands' ),
121
+ defaultValue = None ,
122
+ optional = True )
123
+ src_nodata_param .setFlags (src_nodata_param .flags () | QgsProcessingParameterDefinition .FlagAdvanced )
124
+ self .addParameter (src_nodata_param )
125
+
117
126
self .addParameter (ParameterVrtDestination (self .OUTPUT , QCoreApplication .translate ("ParameterVrtDestination" , 'Virtual' )))
118
127
119
128
def name (self ):
@@ -151,6 +160,10 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
151
160
arguments .append ('-r' )
152
161
arguments .append (self .RESAMPLING_OPTIONS [self .parameterAsEnum (parameters , self .RESAMPLING , context )])
153
162
163
+ if self .SRC_NODATA in parameters and parameters [self .SRC_NODATA ] not in (None , '' ):
164
+ nodata = self .parameterAsString (parameters , self .SRC_NODATA , context )
165
+ arguments .append ('-srcnodata "{}"' .format (nodata ))
166
+
154
167
# Always write input files to a text file in case there are many of them and the
155
168
# length of the command will be longer then allowed in command prompt
156
169
list_file = GdalUtils .writeLayerParameterToTextFile (filename = 'buildvrtInputFiles.txt' , alg = self , parameters = parameters , parameter_name = self .INPUT , context = context , executing = executing , quote = False )
0 commit comments