Skip to content

Commit 49d585e

Browse files
committedMar 21, 2018
[processing][gdal] Move method to write input files to text file to GdalUtils
1 parent b17feaa commit 49d585e

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed
 

‎python/plugins/processing/algs/gdal/GdalUtils.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,3 +397,17 @@ def parseCreationOptions(value):
397397
for p in parts:
398398
options.extend(['-co', p])
399399
return options
400+
401+
@staticmethod
402+
def writeLayerParameterToTextFile(filename, alg, parameters, parameter_name, context, quote=True, executing=False):
403+
listFile = os.path.join(QgsProcessingUtils.tempFolder(), filename)
404+
with open(listFile, 'w') as f:
405+
if executing:
406+
layers = []
407+
for l in alg.parameterAsLayerList(parameters, parameter_name, context):
408+
if quote:
409+
layers.append('"' + l.source() + '"')
410+
else:
411+
layers.append(l.source())
412+
f.write('\n'.join(layers))
413+
return listFile

‎python/plugins/processing/algs/gdal/buildvrt.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,9 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
113113
arguments.append('-allow_projection_difference')
114114
# Always write input files to a text file in case there are many of them and the
115115
# length of the command will be longer then allowed in command prompt
116-
listFile = os.path.join(QgsProcessingUtils.tempFolder(), 'buildvrtInputFiles.txt')
117-
with open(listFile, 'w') as f:
118-
if executing:
119-
layers = []
120-
for l in self.parameterAsLayerList(parameters, self.INPUT, context):
121-
layers.append(l.source())
122-
f.write('\n'.join(layers))
116+
list_file = GdalUtils.writeLayerParameterToTextFile(filename='buildvrtInputFiles.txt', alg=self, parameters=parameters, parameter_name=self.INPUT, context=context, executing=executing, quote=False)
123117
arguments.append('-input_file_list')
124-
arguments.append(listFile)
118+
arguments.append(list_file)
125119

126120
out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
127121
arguments.append(out)

‎python/plugins/processing/algs/gdal/merge.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ def initAlgorithm(self, config=None):
8383
self.addParameter(nodata_param)
8484

8585
nodata_out_param = QgsProcessingParameterNumber(self.NODATA_OUTPUT,
86-
self.tr('Assign specified "nodata" value to output'),
87-
type=QgsProcessingParameterNumber.Integer,
88-
defaultValue=None,
89-
optional=True)
86+
self.tr('Assign specified "nodata" value to output'),
87+
type=QgsProcessingParameterNumber.Integer,
88+
defaultValue=None,
89+
optional=True)
9090
nodata_out_param.setFlags(nodata_out_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
9191
self.addParameter(nodata_out_param)
9292

@@ -159,15 +159,9 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
159159

160160
# Always write input files to a text file in case there are many of them and the
161161
# length of the command will be longer then allowed in command prompt
162-
listFile = os.path.join(QgsProcessingUtils.tempFolder(), 'mergeInputFiles.txt')
163-
with open(listFile, 'w') as f:
164-
if executing:
165-
layers = []
166-
for l in self.parameterAsLayerList(parameters, self.INPUT, context):
167-
layers.append('"' + l.source() + '"')
168-
f.write('\n'.join(layers))
162+
list_file = GdalUtils.writeLayerParameterToTextFile(filename='mergeInputFiles.txt', alg=self, parameters=parameters, parameter_name=self.INPUT, context=context, quote=True, executing=executing)
169163
arguments.append('--optfile')
170-
arguments.append(listFile)
164+
arguments.append(list_file)
171165

172166
commands = []
173167
if isWindows():

0 commit comments

Comments
 (0)
Please sign in to comment.