Skip to content

Commit be60f12

Browse files
committedJan 1, 2019
[processing] expose resampling and format options in the gdaladdo
algorithm (fix #20432) These options actually were here but not added to the UI. (cherry picked from commit 3d33b9f)
1 parent 19d8605 commit be60f12

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed
 

‎python/plugins/processing/algs/gdal/gdaladdo.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from qgis.PyQt.QtGui import QIcon
3131

3232
from qgis.core import (QgsProcessingException,
33+
QgsProcessingParameterDefinition,
3334
QgsProcessingParameterRasterLayer,
3435
QgsProcessingParameterEnum,
3536
QgsProcessingParameterString,
@@ -88,6 +89,9 @@ def initAlgorithm(self, config=None):
8889
options=self.formats,
8990
allowMultiple=False,
9091
defaultValue=0))
92+
for p in params:
93+
p.setFlags(p.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
94+
self.addParameter(p)
9195

9296
self.addOutput(QgsProcessingOutputRasterLayer(self.OUTPUT, self.tr('Pyramidized')))
9397

‎python/plugins/processing/tests/GdalAlgorithmsTest.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
from processing.algs.gdal.warp import warp
6060
from processing.algs.gdal.fillnodata import fillnodata
6161
from processing.algs.gdal.rearrange_bands import rearrange_bands
62+
from processing.algs.gdal.gdaladdo import gdaladdo
63+
6264
from processing.tools.system import isWindows
6365

6466
from qgis.core import (QgsProcessingContext,
@@ -2369,6 +2371,75 @@ def testPointsAlongLines(self):
23692371
'-dialect sqlite -sql "SELECT ST_Line_Interpolate_Point(geometry, 0.2) AS geometry,* FROM \'polys2\'" ' +
23702372
'-f "ESRI Shapefile"'])
23712373

2374+
def testGdalAddo(self):
2375+
context = QgsProcessingContext()
2376+
feedback = QgsProcessingFeedback()
2377+
source = os.path.join(testDataPath, 'dem.tif')
2378+
2379+
with tempfile.TemporaryDirectory() as outdir:
2380+
alg = gdaladdo()
2381+
alg.initAlgorithm()
2382+
2383+
# defaults
2384+
self.assertEqual(
2385+
alg.getConsoleCommands({'INPUT': source,
2386+
'LEVELS': '2 4 8 16',
2387+
'CLEAN': False,
2388+
'RESAMPLING': 0,
2389+
'FORMAT': 0}, context, feedback),
2390+
['gdaladdo',
2391+
source + ' ' + '-r nearest 2 4 8 16'])
2392+
2393+
# with "clean" option
2394+
self.assertEqual(
2395+
alg.getConsoleCommands({'INPUT': source,
2396+
'LEVELS': '2 4 8 16',
2397+
'CLEAN': True,
2398+
'RESAMPLING': 0,
2399+
'FORMAT': 0}, context, feedback),
2400+
['gdaladdo',
2401+
source + ' ' + '-r nearest -clean 2 4 8 16'])
2402+
2403+
# ovr format
2404+
self.assertEqual(
2405+
alg.getConsoleCommands({'INPUT': source,
2406+
'LEVELS': '2 4 8 16',
2407+
'CLEAN': False,
2408+
'RESAMPLING': 0,
2409+
'FORMAT': 1}, context, feedback),
2410+
['gdaladdo',
2411+
source + ' ' + '-r nearest -ro 2 4 8 16'])
2412+
2413+
# Erdas format
2414+
self.assertEqual(
2415+
alg.getConsoleCommands({'INPUT': source,
2416+
'LEVELS': '2 4 8 16',
2417+
'CLEAN': False,
2418+
'RESAMPLING': 0,
2419+
'FORMAT': 2}, context, feedback),
2420+
['gdaladdo',
2421+
source + ' ' + '-r nearest --config USE_RRD YES 2 4 8 16'])
2422+
2423+
# custom resampling method format
2424+
self.assertEqual(
2425+
alg.getConsoleCommands({'INPUT': source,
2426+
'LEVELS': '2 4 8 16',
2427+
'CLEAN': False,
2428+
'RESAMPLING': 4,
2429+
'FORMAT': 0}, context, feedback),
2430+
['gdaladdo',
2431+
source + ' ' + '-r cubicspline 2 4 8 16'])
2432+
2433+
# more levels
2434+
self.assertEqual(
2435+
alg.getConsoleCommands({'INPUT': source,
2436+
'LEVELS': '2 4 8 16 32 64',
2437+
'CLEAN': False,
2438+
'RESAMPLING': 0,
2439+
'FORMAT': 0}, context, feedback),
2440+
['gdaladdo',
2441+
source + ' ' + '-r nearest 2 4 8 16 32 64'])
2442+
23722443

23732444
class TestGdalOgrToPostGis(unittest.TestCase):
23742445

0 commit comments

Comments
 (0)
Please sign in to comment.