mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-15 00:02:52 -04:00
[processing][gdal] Use a text file for input file list to gdal_merge
Otherwise command fails when attempting to merge many rasters due to length of command line. Now the algorithm uses the same approach as buildvrt and creates a text file containing the names of the rasters and then passes this to the gdal_merge command Fixes gdal merge algorithm fails with many input files
This commit is contained in:
parent
95fa89ef70
commit
1d8ecaf79a
@ -36,7 +36,8 @@ from qgis.core import (QgsRasterFileWriter,
|
||||
QgsProcessingParameterEnum,
|
||||
QgsProcessingParameterString,
|
||||
QgsProcessingParameterBoolean,
|
||||
QgsProcessingParameterRasterDestination)
|
||||
QgsProcessingParameterRasterDestination,
|
||||
QgsProcessingUtils)
|
||||
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
|
||||
from processing.algs.gdal.GdalUtils import GdalUtils
|
||||
|
||||
@ -105,7 +106,6 @@ class merge(GdalAlgorithm):
|
||||
return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', 'merge.png'))
|
||||
|
||||
def getConsoleCommands(self, parameters, context, feedback, executing=True):
|
||||
layers = self.parameterAsLayerList(parameters, self.INPUT, context)
|
||||
out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
|
||||
|
||||
arguments = []
|
||||
@ -128,8 +128,17 @@ class merge(GdalAlgorithm):
|
||||
arguments.append('-o')
|
||||
arguments.append(out)
|
||||
|
||||
for layer in layers:
|
||||
arguments.append(layer.source())
|
||||
# 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))
|
||||
arguments.append('--optfile')
|
||||
arguments.append(listFile)
|
||||
|
||||
commands = []
|
||||
if isWindows():
|
||||
|
Loading…
x
Reference in New Issue
Block a user