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$'
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
|
|
|
def defineCharacteristics(self):
|
2013-10-01 20:52:22 +03:00
|
|
|
self.name = 'Near black'
|
|
|
|
self.group = '[GDAL] Analysis'
|
2015-01-13 10:49:08 +02:00
|
|
|
self.addParameter(ParameterRaster(nearblack.INPUT,
|
|
|
|
self.tr('Input layer'), False))
|
2013-10-01 20:52:22 +03:00
|
|
|
self.addParameter(ParameterNumber(nearblack.NEAR,
|
2015-01-13 10:49:08 +02:00
|
|
|
self.tr('How far from black (white)'), 0, None, 15))
|
2013-10-01 20:52:22 +03:00
|
|
|
self.addParameter(ParameterBoolean(nearblack.WHITE,
|
2015-01-13 10:49:08 +02:00
|
|
|
self.tr('Search for nearly white pixels instead of nearly black'),
|
|
|
|
False))
|
2015-04-10 09:44:20 +02:00
|
|
|
self.addOutput(OutputRaster(nearblack.OUTPUT, self.tr('Nearblack')))
|
2012-09-15 18:25:25 +03:00
|
|
|
|
|
|
|
def processAlgorithm(self, progress):
|
2013-04-10 12:15:55 +04:00
|
|
|
arguments = []
|
2013-10-01 20:52:22 +03:00
|
|
|
arguments.append('-o')
|
2013-04-10 12:15:55 +04:00
|
|
|
arguments.append(self.getOutputValue(nearblack.OUTPUT))
|
2013-10-01 20:52:22 +03:00
|
|
|
arguments.append('-near')
|
2013-04-10 12:15:55 +04:00
|
|
|
arguments.append(str(self.getParameterValue(nearblack.NEAR)))
|
2012-09-15 18:25:25 +03:00
|
|
|
if self.getParameterValue(nearblack.WHITE):
|
2013-10-01 20:52:22 +03:00
|
|
|
arguments.append('-white')
|
2013-04-10 12:15:55 +04:00
|
|
|
arguments.append(self.getParameterValue(nearblack.INPUT))
|
2013-10-01 20:52:22 +03:00
|
|
|
GdalUtils.runGdal(['nearblack', GdalUtils.escapeAndJoin(arguments)],
|
|
|
|
progress)
|