2012-11-10 00:31:01 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
***************************************************************************
|
|
|
|
translate.py
|
|
|
|
---------------------
|
|
|
|
Date : August 2012
|
|
|
|
Copyright : (C) 2012 by Victor Olaya
|
|
|
|
Email : volayaf at gmail dot com
|
|
|
|
***************************************************************************
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
***************************************************************************
|
|
|
|
"""
|
|
|
|
|
|
|
|
__author__ = 'Victor Olaya'
|
|
|
|
__date__ = 'August 2012'
|
|
|
|
__copyright__ = '(C) 2012, Victor Olaya'
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2012-11-10 00:31:01 +01:00
|
|
|
# This will get replaced with a git SHA1 when you do a git archive
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2012-11-10 00:31:01 +01:00
|
|
|
__revision__ = '$Format:%H$'
|
|
|
|
|
2016-01-25 15:42:11 +02:00
|
|
|
import os
|
|
|
|
|
2016-04-22 10:38:48 +02:00
|
|
|
from qgis.PyQt.QtGui import QIcon
|
2016-01-25 15:42:11 +02:00
|
|
|
|
2014-06-02 00:35:49 +02:00
|
|
|
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
|
2014-07-14 14:19:09 +02:00
|
|
|
from processing.core.parameters import ParameterRaster
|
|
|
|
from processing.core.parameters import ParameterBoolean
|
|
|
|
from processing.core.parameters import ParameterSelection
|
|
|
|
from processing.core.parameters import ParameterString
|
|
|
|
from processing.core.outputs import OutputRaster
|
2013-04-10 12:15:55 +04:00
|
|
|
|
2014-04-17 01:41:25 +02:00
|
|
|
from processing.algs.gdal.GdalUtils import GdalUtils
|
2012-11-10 00:31:01 +01:00
|
|
|
|
2016-01-25 15:42:11 +02:00
|
|
|
pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]
|
|
|
|
|
2012-12-10 00:12:07 +01:00
|
|
|
|
2014-06-02 00:35:49 +02:00
|
|
|
class gdaladdo(GdalAlgorithm):
|
2013-09-14 16:04:37 +03:00
|
|
|
|
2013-10-01 20:52:22 +03:00
|
|
|
INPUT = 'INPUT'
|
|
|
|
LEVELS = 'LEVELS'
|
|
|
|
CLEAN = 'CLEAN'
|
|
|
|
RESAMPLING_METHOD = 'RESAMPLING_METHOD'
|
|
|
|
FORMAT = 'FORMAT'
|
|
|
|
OUTPUT = 'OUTPUT'
|
|
|
|
|
|
|
|
METHODS = [
|
|
|
|
'nearest',
|
|
|
|
'average',
|
|
|
|
'gauss',
|
|
|
|
'cubic',
|
|
|
|
'average_mp',
|
|
|
|
'average_magphase',
|
|
|
|
'mode',
|
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
--exclude="ui_*.py,debian/*,python/ext-libs/*" \
.
2015-02-01 14:15:42 +01:00
|
|
|
]
|
2013-10-01 20:52:22 +03:00
|
|
|
|
|
|
|
FORMATS = ['Internal (if possible)', 'External (GTiff .ovr)',
|
|
|
|
'External (ERDAS Imagine .aux)']
|
2012-11-10 00:31:01 +01:00
|
|
|
|
2017-03-29 10:42:42 +10:00
|
|
|
def icon(self):
|
2016-01-25 15:42:11 +02:00
|
|
|
return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', 'raster-overview.png'))
|
|
|
|
|
2017-03-29 12:51:59 +10:00
|
|
|
def name(self):
|
2017-03-29 17:09:39 +10:00
|
|
|
return 'overviews'
|
2017-03-29 12:51:59 +10:00
|
|
|
|
|
|
|
def displayName(self):
|
|
|
|
return self.tr('Build overviews (pyramids)')
|
|
|
|
|
2017-03-29 12:04:09 +10:00
|
|
|
def group(self):
|
|
|
|
return self.tr('Raster miscellaneous')
|
|
|
|
|
2012-11-10 00:31:01 +01:00
|
|
|
def defineCharacteristics(self):
|
2015-01-13 10:49:08 +02:00
|
|
|
self.addParameter(ParameterRaster(
|
|
|
|
self.INPUT, self.tr('Input layer'), False))
|
|
|
|
self.addParameter(ParameterString(self.LEVELS,
|
2015-08-22 14:29:41 +02:00
|
|
|
self.tr('Overview levels'), '2 4 8 16'))
|
2013-10-01 20:52:22 +03:00
|
|
|
self.addParameter(ParameterBoolean(self.CLEAN,
|
2015-08-22 14:29:41 +02:00
|
|
|
self.tr('Remove all existing overviews'), False))
|
2013-10-01 20:52:22 +03:00
|
|
|
self.addParameter(ParameterSelection(self.RESAMPLING_METHOD,
|
2015-08-22 14:29:41 +02:00
|
|
|
self.tr('Resampling method'), self.METHODS, 0))
|
2015-01-13 10:49:08 +02:00
|
|
|
self.addParameter(ParameterSelection(self.FORMAT,
|
2015-08-22 14:29:41 +02:00
|
|
|
self.tr('Overview format'), self.FORMATS, 0))
|
2015-04-10 09:44:20 +02:00
|
|
|
self.addOutput(OutputRaster(self.OUTPUT, self.tr('Pyramidized'), True))
|
2012-11-10 00:31:01 +01:00
|
|
|
|
2015-05-07 13:14:01 +02:00
|
|
|
def getConsoleCommands(self):
|
2013-09-14 16:04:37 +03:00
|
|
|
inFile = self.getParameterValue(self.INPUT)
|
|
|
|
clearOverviews = self.getParameterValue(self.CLEAN)
|
|
|
|
ovrFormat = self.getParameterValue(self.FORMAT)
|
|
|
|
|
2013-04-10 12:15:55 +04:00
|
|
|
arguments = []
|
|
|
|
arguments.append(inFile)
|
2013-09-14 16:04:37 +03:00
|
|
|
if clearOverviews:
|
2013-10-01 20:52:22 +03:00
|
|
|
arguments.append('-clean')
|
|
|
|
arguments.append('-r')
|
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
--exclude="ui_*.py,debian/*,python/ext-libs/*" \
.
2015-02-01 14:15:42 +01:00
|
|
|
arguments.append(self.METHODS[self.getParameterValue(self.RESAMPLING_METHOD)])
|
2013-09-14 16:04:37 +03:00
|
|
|
|
|
|
|
if ovrFormat == 1:
|
|
|
|
# external .ovr
|
2013-10-01 20:52:22 +03:00
|
|
|
arguments.append('-ro')
|
2013-09-14 16:04:37 +03:00
|
|
|
elif ovrFormat == 2:
|
|
|
|
# external .aux
|
2013-10-01 20:52:22 +03:00
|
|
|
arguments.extend('--config USE_RRD YES'.split(' '))
|
2013-09-14 16:04:37 +03:00
|
|
|
|
2013-10-01 20:52:22 +03:00
|
|
|
arguments.extend(self.getParameterValue(self.LEVELS).split(' '))
|
2013-09-14 16:04:37 +03:00
|
|
|
self.setOutputValue(self.OUTPUT, inFile)
|
2012-11-10 00:31:01 +01:00
|
|
|
|
2015-05-07 13:14:01 +02:00
|
|
|
return ['gdaladdo', GdalUtils.escapeAndJoin(arguments)]
|