mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
[processing][gdal] Move method to write input files to text file to GdalUtils
This commit is contained in:
parent
b17feaaa97
commit
49d585ef17
@ -397,3 +397,17 @@ class GdalUtils:
|
|||||||
for p in parts:
|
for p in parts:
|
||||||
options.extend(['-co', p])
|
options.extend(['-co', p])
|
||||||
return options
|
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 @@ class buildvrt(GdalAlgorithm):
|
|||||||
arguments.append('-allow_projection_difference')
|
arguments.append('-allow_projection_difference')
|
||||||
# Always write input files to a text file in case there are many of them and the
|
# 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
|
# length of the command will be longer then allowed in command prompt
|
||||||
listFile = os.path.join(QgsProcessingUtils.tempFolder(), 'buildvrtInputFiles.txt')
|
list_file = GdalUtils.writeLayerParameterToTextFile(filename='buildvrtInputFiles.txt', alg=self, parameters=parameters, parameter_name=self.INPUT, context=context, executing=executing, quote=False)
|
||||||
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))
|
|
||||||
arguments.append('-input_file_list')
|
arguments.append('-input_file_list')
|
||||||
arguments.append(listFile)
|
arguments.append(list_file)
|
||||||
|
|
||||||
out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
|
out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
|
||||||
arguments.append(out)
|
arguments.append(out)
|
||||||
|
@ -83,10 +83,10 @@ class merge(GdalAlgorithm):
|
|||||||
self.addParameter(nodata_param)
|
self.addParameter(nodata_param)
|
||||||
|
|
||||||
nodata_out_param = QgsProcessingParameterNumber(self.NODATA_OUTPUT,
|
nodata_out_param = QgsProcessingParameterNumber(self.NODATA_OUTPUT,
|
||||||
self.tr('Assign specified "nodata" value to output'),
|
self.tr('Assign specified "nodata" value to output'),
|
||||||
type=QgsProcessingParameterNumber.Integer,
|
type=QgsProcessingParameterNumber.Integer,
|
||||||
defaultValue=None,
|
defaultValue=None,
|
||||||
optional=True)
|
optional=True)
|
||||||
nodata_out_param.setFlags(nodata_out_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
|
nodata_out_param.setFlags(nodata_out_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
|
||||||
self.addParameter(nodata_out_param)
|
self.addParameter(nodata_out_param)
|
||||||
|
|
||||||
@ -159,15 +159,9 @@ class merge(GdalAlgorithm):
|
|||||||
|
|
||||||
# Always write input files to a text file in case there are many of them and the
|
# 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
|
# length of the command will be longer then allowed in command prompt
|
||||||
listFile = os.path.join(QgsProcessingUtils.tempFolder(), 'mergeInputFiles.txt')
|
list_file = GdalUtils.writeLayerParameterToTextFile(filename='mergeInputFiles.txt', alg=self, parameters=parameters, parameter_name=self.INPUT, context=context, quote=True, executing=executing)
|
||||||
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))
|
|
||||||
arguments.append('--optfile')
|
arguments.append('--optfile')
|
||||||
arguments.append(listFile)
|
arguments.append(list_file)
|
||||||
|
|
||||||
commands = []
|
commands = []
|
||||||
if isWindows():
|
if isWindows():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user