Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #8766 from alexbruy/processing-gdaladdo
[processing][needs-docs] expose resampling and format options in the gdaladdo (fix #20432)
  • Loading branch information
alexbruy committed Jan 1, 2019
2 parents f07c264 + c643837 commit 1233a21
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 2 deletions.
10 changes: 8 additions & 2 deletions python/plugins/processing/algs/gdal/gdaladdo.py
Expand Up @@ -30,6 +30,7 @@
from qgis.PyQt.QtGui import QIcon

from qgis.core import (QgsProcessingException,
QgsProcessingParameterDefinition,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterEnum,
QgsProcessingParameterString,
Expand Down Expand Up @@ -82,12 +83,17 @@ def initAlgorithm(self, config=None):
self.tr('Resampling method'),
options=[i[0] for i in self.methods],
allowMultiple=False,
defaultValue=0))
defaultValue=0,
optional=True))
params.append(QgsProcessingParameterEnum(self.FORMAT,
self.tr('Overviews format'),
options=self.formats,
allowMultiple=False,
defaultValue=0))
defaultValue=0,
optional=True))
for p in params:
p.setFlags(p.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
self.addParameter(p)

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

Expand Down
79 changes: 79 additions & 0 deletions python/plugins/processing/tests/GdalAlgorithmsTest.py
Expand Up @@ -59,6 +59,8 @@
from processing.algs.gdal.warp import warp
from processing.algs.gdal.fillnodata import fillnodata
from processing.algs.gdal.rearrange_bands import rearrange_bands
from processing.algs.gdal.gdaladdo import gdaladdo

from processing.tools.system import isWindows

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

def testGdalAddo(self):
context = QgsProcessingContext()
feedback = QgsProcessingFeedback()
source = os.path.join(testDataPath, 'dem.tif')

with tempfile.TemporaryDirectory() as outdir:
alg = gdaladdo()
alg.initAlgorithm()

# defaults
self.assertEqual(
alg.getConsoleCommands({'INPUT': source,
'LEVELS': '2 4 8 16',
'CLEAN': False,
'RESAMPLING': 0,
'FORMAT': 0}, context, feedback),
['gdaladdo',
source + ' ' + '-r nearest 2 4 8 16'])

# with "clean" option
self.assertEqual(
alg.getConsoleCommands({'INPUT': source,
'LEVELS': '2 4 8 16',
'CLEAN': True,
'RESAMPLING': 0,
'FORMAT': 0}, context, feedback),
['gdaladdo',
source + ' ' + '-r nearest -clean 2 4 8 16'])

# ovr format
self.assertEqual(
alg.getConsoleCommands({'INPUT': source,
'LEVELS': '2 4 8 16',
'CLEAN': False,
'RESAMPLING': 0,
'FORMAT': 1}, context, feedback),
['gdaladdo',
source + ' ' + '-r nearest -ro 2 4 8 16'])

# Erdas format
self.assertEqual(
alg.getConsoleCommands({'INPUT': source,
'LEVELS': '2 4 8 16',
'CLEAN': False,
'RESAMPLING': 0,
'FORMAT': 2}, context, feedback),
['gdaladdo',
source + ' ' + '-r nearest --config USE_RRD YES 2 4 8 16'])

# custom resampling method format
self.assertEqual(
alg.getConsoleCommands({'INPUT': source,
'LEVELS': '2 4 8 16',
'CLEAN': False,
'RESAMPLING': 4,
'FORMAT': 0}, context, feedback),
['gdaladdo',
source + ' ' + '-r cubicspline 2 4 8 16'])

# more levels
self.assertEqual(
alg.getConsoleCommands({'INPUT': source,
'LEVELS': '2 4 8 16 32 64',
'CLEAN': False,
'RESAMPLING': 0,
'FORMAT': 0}, context, feedback),
['gdaladdo',
source + ' ' + '-r nearest 2 4 8 16 32 64'])

# without advanced params
self.assertEqual(
alg.getConsoleCommands({'INPUT': source,
'LEVELS': '2 4 8 16',
'CLEAN': False}, context, feedback),
['gdaladdo',
source + ' ' + '-r nearest 2 4 8 16'])


class TestGdalOgrToPostGis(unittest.TestCase):

Expand Down

0 comments on commit 1233a21

Please sign in to comment.