Skip to content
Permalink
Browse files

[processing][gdal] Move method to write input files to text file to G…

…dalUtils

(cherry-picked from 49d585)
  • Loading branch information
nyalldawson committed Mar 21, 2018
1 parent 6604def commit bffc69954cbd9459cf670034a6fe7d36c12ac178
@@ -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
@@ -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)
@@ -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)

@@ -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():

0 comments on commit bffc699

Please sign in to comment.
You can’t perform that action at this time.