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'
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2012-10-04 19:33:47 +02:00
|
|
|
# This will get replaced with a git SHA1 when you do a git archive
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2012-10-04 19:33:47 +02: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 ParameterNumber
|
|
|
|
from processing.core.parameters import ParameterBoolean
|
|
|
|
from processing.core.outputs import OutputRaster
|
2014-04-17 01:41:25 +02:00
|
|
|
from processing.algs.gdal.GdalUtils import GdalUtils
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2016-01-25 15:42:11 +02:00
|
|
|
pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]
|
|
|
|
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2014-06-02 00:35:49 +02:00
|
|
|
class nearblack(GdalAlgorithm):
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2013-10-01 20:52:22 +03:00
|
|
|
INPUT = 'INPUT'
|
|
|
|
OUTPUT = 'OUTPUT'
|
|
|
|
NEAR = 'NEAR'
|
|
|
|
WHITE = 'WHITE'
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2016-01-25 15:42:11 +02: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):
|
2015-07-26 03:48:27 +02:00
|
|
|
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,
|
2015-08-22 14:29:41 +02:00
|
|
|
self.tr('Input layer'), False))
|
2016-02-08 19:02:17 +00:00
|
|
|
self.addParameter(ParameterNumber(self.NEAR,
|
2015-08-22 14:29:41 +02:00
|
|
|
self.tr('How far from black (white)'), 0, None, 15))
|
2016-02-08 19:02:17 +00:00
|
|
|
self.addParameter(ParameterBoolean(self.WHITE,
|
2015-08-22 14:29:41 +02:00
|
|
|
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
|
|
|
|
2015-05-07 13:14:01 +02:00
|
|
|
def getConsoleCommands(self):
|
2013-04-10 12:15:55 +04:00
|
|
|
arguments = []
|
2013-10-01 20:52:22 +03:00
|
|
|
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))
|
2013-10-01 20:52:22 +03:00
|
|
|
arguments.append('-near')
|
2016-02-08 19:02:17 +00:00
|
|
|
arguments.append(unicode(self.getParameterValue(self.NEAR)))
|
|
|
|
if self.getParameterValue(self.WHITE):
|
2013-10-01 20:52:22 +03:00
|
|
|
arguments.append('-white')
|
2016-02-08 19:02:17 +00:00
|
|
|
arguments.append(self.getParameterValue(self.INPUT))
|
2015-05-07 13:14:01 +02:00
|
|
|
return ['nearblack', GdalUtils.escapeAndJoin(arguments)]
|