77 lines
3.0 KiB
Python
Raw Normal View History

2012-10-04 19:33:47 +02:00
# -*- coding: utf-8 -*-
"""
***************************************************************************
nearblack.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'
2012-10-04 19:33:47 +02:00
# This will get replaced with a git SHA1 when you do a git archive
2012-10-04 19:33:47 +02:00
__revision__ = '$Format:%H$'
import os
2016-04-22 10:38:48 +02:00
from qgis.PyQt.QtGui import QIcon
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
from processing.core.parameters import ParameterRaster
from processing.core.parameters import ParameterNumber
from processing.core.parameters import ParameterBoolean
from processing.core.outputs import OutputRaster
from processing.algs.gdal.GdalUtils import GdalUtils
2012-09-15 18:25:25 +03:00
pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]
class nearblack(GdalAlgorithm):
2012-09-15 18:25:25 +03:00
INPUT = 'INPUT'
OUTPUT = 'OUTPUT'
NEAR = 'NEAR'
WHITE = 'WHITE'
2012-09-15 18:25:25 +03:00
def getIcon(self):
return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', 'nearblack.png'))
2012-09-15 18:25:25 +03:00
def defineCharacteristics(self):
self.name, self.i18n_name = self.trAlgorithm('Near black')
self.group, self.i18n_group = self.trAlgorithm('[GDAL] Analysis')
2016-02-08 19:02:17 +00:00
self.addParameter(ParameterRaster(self.INPUT,
self.tr('Input layer'), False))
2016-02-08 19:02:17 +00:00
self.addParameter(ParameterNumber(self.NEAR,
self.tr('How far from black (white)'), 0, None, 15))
2016-02-08 19:02:17 +00:00
self.addParameter(ParameterBoolean(self.WHITE,
self.tr('Search for nearly white pixels instead of nearly black'),
False))
2016-02-08 19:02:17 +00:00
self.addOutput(OutputRaster(self.OUTPUT, self.tr('Nearblack')))
2012-09-15 18:25:25 +03:00
def getConsoleCommands(self):
arguments = []
arguments.append('-o')
2016-02-08 19:02:17 +00:00
output = unicode(self.getOutputValue(self.OUTPUT))
arguments.append(output)
arguments.append('-of')
2016-02-09 14:19:07 +01:00
arguments.append(GdalUtils.getFormatShortNameFromFilename(output))
arguments.append('-near')
2016-02-08 19:02:17 +00:00
arguments.append(unicode(self.getParameterValue(self.NEAR)))
if self.getParameterValue(self.WHITE):
arguments.append('-white')
2016-02-08 19:02:17 +00:00
arguments.append(self.getParameterValue(self.INPUT))
return ['nearblack', GdalUtils.escapeAndJoin(arguments)]