Skip to content
Permalink
Browse files

[processing] impove Build Pyramids algorithm

  • Loading branch information
alexbruy committed Sep 14, 2013
1 parent 65b5b01 commit 69931cf559c6f16df96057dd09475f45cf55b45b
Showing with 37 additions and 6 deletions.
  1. +37 −6 python/plugins/processing/gdal/gdaladdo.py
@@ -30,6 +30,8 @@

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.parameters.ParameterRaster import ParameterRaster
from processing.parameters.ParameterBoolean import ParameterBoolean
from processing.parameters.ParameterSelection import ParameterSelection
from processing.outputs.OutputRaster import OutputRaster

from processing.gdal.GdalUtils import GdalUtils
@@ -38,8 +40,19 @@ class gdaladdo(GeoAlgorithm):

INPUT = "INPUT"
LEVELS = "LEVELS"
CLEAN = "CLEAN"
RESAMPLING_METHOD = "RESAMPLING_METHOD"
FORMAT = "FORMAT"
OUTPUT = "OUTPUT"

METHODS = ["nearest", "average", "gauss", "cubic", "average_mp",
"average_magphase", "mode"
]

FORMATS = ["Internal (if possible)",
"External (GTiff .ovr)",
"External (ERDAS Imagine .aux)"
]

def getIcon(self):
filepath = os.path.dirname(__file__) + "/icons/raster-overview.png"
@@ -48,15 +61,33 @@ def getIcon(self):
def defineCharacteristics(self):
self.name = "Build pyramids (overviews)"
self.group = "[GDAL] Miscellaneous"
self.addParameter(ParameterRaster(gdaladdo.INPUT, "Input layer", False))
self.addParameter(ParameterString(gdaladdo.LEVELS, "Overview levels", "2 4 8 16"))
self.addOutput(OutputRaster(gdaladdo.OUTPUT, "Output layer", True))
self.addParameter(ParameterRaster(self.INPUT, "Input layer", False))
self.addParameter(ParameterString(self.LEVELS, "Overview levels", "2 4 8 16"))
self.addParameter(ParameterBoolean(self.CLEAN, "Remove all existing overviews", False))
self.addParameter(ParameterSelection(self.RESAMPLING_METHOD, "Resampling method", self.METHODS, 0))
self.addParameter(ParameterSelection(self.FORMAT, "Overview format", self.FORMATS, 0))
self.addOutput(OutputRaster(self.OUTPUT, "Output layer", True))

def processAlgorithm(self, progress):
inFile = self.getParameterValue(self.INPUT)
clearOverviews = self.getParameterValue(self.CLEAN)
ovrFormat = self.getParameterValue(self.FORMAT)

arguments = []
inFile = self.getParameterValue(gdaladdo.INPUT)
arguments.append(inFile)
arguments.extend(self.getParameterValue(gdaladdo.LEVELS).split(" "))
self.setOutputValue(gdaladdo.OUTPUT, inFile)
if clearOverviews:
arguments.append("-clean")
arguments.append("-r")
arguments.append(self.METHODS[self.getParameterValue(self.RESAMPLING_METHOD)])

if ovrFormat == 1:
# external .ovr
arguments.append("-ro")
elif ovrFormat == 2:
# external .aux
arguments.extend("--config USE_RRD YES".split(" "))

arguments.extend(self.getParameterValue(self.LEVELS).split(" "))
self.setOutputValue(self.OUTPUT, inFile)

GdalUtils.runGdal(["gdaladdo", GdalUtils.escapeAndJoin(arguments)], progress)

0 comments on commit 69931cf

Please sign in to comment.
You can’t perform that action at this time.