Use gdal_merge.py for GDAL < 3.9

This commit is contained in:
Nyall Dawson 2025-09-29 10:59:13 +10:00
parent e2a955eee2
commit 833aace899
No known key found for this signature in database
GPG Key ID: AEA7D60D3DF12896
2 changed files with 20 additions and 5 deletions

View File

@ -266,6 +266,19 @@ class merge(GdalAlgorithm):
arguments.append(list_file) arguments.append(list_file)
return [ return [
self.commandName() + (".bat" if isWindows() else ""), self.commandName() + merge.command_ext(),
GdalUtils.escapeAndJoin(arguments), GdalUtils.escapeAndJoin(arguments),
] ]
@staticmethod
def command_ext() -> str:
"""
Returns the gdal_merge command extension
"""
if isWindows():
return ".bat"
if GdalUtils.version() < 3090000:
return ".py"
return ""

View File

@ -4866,6 +4866,8 @@ class TestGdalRasterAlgorithms(QgisTestCase, AlgorithmsTestBase.AlgorithmsTest):
alg = merge() alg = merge()
alg.initAlgorithm() alg.initAlgorithm()
merge_command = alg.commandName() + alg.command_ext()
with tempfile.TemporaryDirectory() as outdir: with tempfile.TemporaryDirectory() as outdir:
# this algorithm creates temporary text file with input layers # this algorithm creates temporary text file with input layers
# so we strip its path, leaving only filename # so we strip its path, leaving only filename
@ -4877,7 +4879,7 @@ class TestGdalRasterAlgorithms(QgisTestCase, AlgorithmsTestBase.AlgorithmsTest):
self.assertEqual( self.assertEqual(
cmd, cmd,
[ [
"gdal_merge", merge_command,
"-ot Float32 -of GTiff " "-ot Float32 -of GTiff "
+ "-o " + "-o "
+ outdir + outdir
@ -4896,7 +4898,7 @@ class TestGdalRasterAlgorithms(QgisTestCase, AlgorithmsTestBase.AlgorithmsTest):
self.assertEqual( self.assertEqual(
cmd, cmd,
[ [
"gdal_merge", merge_command,
"-separate -ot Float32 -of GTiff " "-separate -ot Float32 -of GTiff "
+ "-o " + "-o "
+ outdir + outdir
@ -4920,7 +4922,7 @@ class TestGdalRasterAlgorithms(QgisTestCase, AlgorithmsTestBase.AlgorithmsTest):
self.assertEqual( self.assertEqual(
cmd, cmd,
[ [
"gdal_merge", merge_command,
"-ot Float32 -of GTiff -tap -ps 0.1 0.1 " "-ot Float32 -of GTiff -tap -ps 0.1 0.1 "
+ "-o " + "-o "
+ outdir + outdir
@ -4944,7 +4946,7 @@ class TestGdalRasterAlgorithms(QgisTestCase, AlgorithmsTestBase.AlgorithmsTest):
self.assertEqual( self.assertEqual(
cmd, cmd,
[ [
"gdal_merge", merge_command,
"-a_nodata -9999.0 -ot Float32 -of GTiff " "-a_nodata -9999.0 -ot Float32 -of GTiff "
+ "-o " + "-o "
+ outdir + outdir