Skip to content

Commit

Permalink
[processing][gdal] Move method to write input files to text file to G…
Browse files Browse the repository at this point in the history
…dalUtils
  • Loading branch information
nyalldawson committed Mar 21, 2018
1 parent b17feaa commit 49d585e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
14 changes: 14 additions & 0 deletions python/plugins/processing/algs/gdal/GdalUtils.py
Expand Up @@ -397,3 +397,17 @@ def parseCreationOptions(value):
for p in parts:
options.extend(['-co', p])
return options

@staticmethod
def writeLayerParameterToTextFile(filename, alg, parameters, parameter_name, context, quote=True, executing=False):
listFile = os.path.join(QgsProcessingUtils.tempFolder(), filename)
with open(listFile, 'w') as f:
if executing:
layers = []
for l in alg.parameterAsLayerList(parameters, parameter_name, context):
if quote:
layers.append('"' + l.source() + '"')
else:
layers.append(l.source())
f.write('\n'.join(layers))
return listFile
10 changes: 2 additions & 8 deletions python/plugins/processing/algs/gdal/buildvrt.py
Expand Up @@ -113,15 +113,9 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append('-allow_projection_difference')
# Always write input files to a text file in case there are many of them and the
# length of the command will be longer then allowed in command prompt
listFile = os.path.join(QgsProcessingUtils.tempFolder(), 'buildvrtInputFiles.txt')
with open(listFile, 'w') as f:
if executing:
layers = []
for l in self.parameterAsLayerList(parameters, self.INPUT, context):
layers.append(l.source())
f.write('\n'.join(layers))
list_file = GdalUtils.writeLayerParameterToTextFile(filename='buildvrtInputFiles.txt', alg=self, parameters=parameters, parameter_name=self.INPUT, context=context, executing=executing, quote=False)
arguments.append('-input_file_list')
arguments.append(listFile)
arguments.append(list_file)

out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
arguments.append(out)
Expand Down
18 changes: 6 additions & 12 deletions python/plugins/processing/algs/gdal/merge.py
Expand Up @@ -83,10 +83,10 @@ def initAlgorithm(self, config=None):
self.addParameter(nodata_param)

nodata_out_param = QgsProcessingParameterNumber(self.NODATA_OUTPUT,
self.tr('Assign specified "nodata" value to output'),
type=QgsProcessingParameterNumber.Integer,
defaultValue=None,
optional=True)
self.tr('Assign specified "nodata" value to output'),
type=QgsProcessingParameterNumber.Integer,
defaultValue=None,
optional=True)
nodata_out_param.setFlags(nodata_out_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
self.addParameter(nodata_out_param)

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

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

commands = []
if isWindows():
Expand Down

0 comments on commit 49d585e

Please sign in to comment.