2012-10-27 23:06:38 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
***************************************************************************
|
|
|
|
SplitRGBBands.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-27 23:06:38 +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-27 23:06:38 +02:00
|
|
|
__revision__ = '$Format:%H$'
|
|
|
|
|
2013-10-01 20:52:22 +03:00
|
|
|
import os
|
2012-10-27 23:06:38 +02:00
|
|
|
from PyQt4 import QtGui
|
2013-08-12 20:44:27 +02:00
|
|
|
from processing.core.GeoAlgorithm import GeoAlgorithm
|
2014-07-14 14:19:09 +02:00
|
|
|
from processing.core.parameters import ParameterRaster
|
|
|
|
from processing.core.outputs import OutputRaster
|
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
|
|
|
from processing.tools.system import getTempFilename, isWindows
|
2014-12-19 15:01:02 +01:00
|
|
|
import SagaUtils
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2012-10-27 23:06:38 +02:00
|
|
|
|
|
|
|
class SplitRGBBands(GeoAlgorithm):
|
|
|
|
|
2013-10-01 20:52:22 +03:00
|
|
|
INPUT = 'INPUT'
|
|
|
|
R = 'R'
|
|
|
|
G = 'G'
|
|
|
|
B = 'B'
|
2012-10-27 23:06:38 +02:00
|
|
|
|
|
|
|
def getIcon(self):
|
2014-04-24 17:25:36 +02:00
|
|
|
return QtGui.QIcon(os.path.dirname(__file__) + '/../../images/saga.png')
|
2012-10-27 23:06:38 +02:00
|
|
|
|
|
|
|
def defineCharacteristics(self):
|
2013-10-01 20:52:22 +03:00
|
|
|
self.name = 'Split RGB bands'
|
|
|
|
self.group = 'Grid - Tools'
|
2015-01-16 16:25:12 +02:00
|
|
|
self.addParameter(ParameterRaster(SplitRGBBands.INPUT,
|
|
|
|
self.tr('Input layer'), False))
|
|
|
|
self.addOutput(OutputRaster(SplitRGBBands.R,
|
|
|
|
self.tr('Output R band layer')))
|
|
|
|
self.addOutput(OutputRaster(SplitRGBBands.G,
|
|
|
|
self.tr('Output G band layer')))
|
|
|
|
self.addOutput(OutputRaster(SplitRGBBands.B,
|
|
|
|
self.tr('Output B band layer')))
|
2012-10-27 23:06:38 +02:00
|
|
|
|
|
|
|
def processAlgorithm(self, progress):
|
2013-10-01 20:52:22 +03:00
|
|
|
# TODO: check correct num of bands
|
2012-12-10 00:12:07 +01:00
|
|
|
input = self.getParameterValue(SplitRGBBands.INPUT)
|
2013-10-01 20:52:22 +03:00
|
|
|
temp = getTempFilename(None).replace('.', '')
|
2013-03-12 20:01:29 +01:00
|
|
|
basename = os.path.basename(temp)
|
2013-10-01 20:52:22 +03:00
|
|
|
validChars = \
|
|
|
|
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
|
2013-09-14 14:25:58 +02:00
|
|
|
safeBasename = ''.join(c for c in basename if c in validChars)
|
2013-03-12 20:01:29 +01:00
|
|
|
temp = os.path.join(os.path.dirname(temp), safeBasename)
|
2013-03-26 14:15:12 +01:00
|
|
|
|
2012-10-27 23:06:38 +02:00
|
|
|
r = self.getOutputValue(SplitRGBBands.R)
|
|
|
|
g = self.getOutputValue(SplitRGBBands.G)
|
|
|
|
b = self.getOutputValue(SplitRGBBands.B)
|
|
|
|
commands = []
|
2013-09-12 13:19:00 +02:00
|
|
|
if isWindows():
|
2013-10-01 20:52:22 +03:00
|
|
|
commands.append('io_gdal 0 -GRIDS "' + temp + '" -FILES "' + input
|
|
|
|
+ '"')
|
|
|
|
commands.append('io_gdal 1 -GRIDS "' + temp
|
|
|
|
+ '_0001.sgrd" -FORMAT 1 -TYPE 0 -FILE "' + r + '"'
|
|
|
|
)
|
|
|
|
commands.append('io_gdal 1 -GRIDS "' + temp
|
|
|
|
+ '_0002.sgrd" -FORMAT 1 -TYPE 0 -FILE "' + g + '"'
|
|
|
|
)
|
|
|
|
commands.append('io_gdal 1 -GRIDS "' + temp
|
|
|
|
+ '_0003.sgrd" -FORMAT 1 -TYPE 0 -FILE "' + b + '"'
|
|
|
|
)
|
2012-10-27 23:06:38 +02:00
|
|
|
else:
|
2013-10-01 20:52:22 +03:00
|
|
|
commands.append('libio_gdal 0 -GRIDS "' + temp + '" -FILES "'
|
|
|
|
+ input + '"')
|
|
|
|
commands.append('libio_gdal 1 -GRIDS "' + temp
|
|
|
|
+ '_0001.sgrd" -FORMAT 1 -TYPE 0 -FILE "' + r + '"'
|
|
|
|
)
|
|
|
|
commands.append('libio_gdal 1 -GRIDS "' + temp
|
|
|
|
+ '_0002.sgrd" -FORMAT 1 -TYPE 0 -FILE "' + g + '"'
|
|
|
|
)
|
|
|
|
commands.append('libio_gdal 1 -GRIDS "' + temp
|
|
|
|
+ '_0003.sgrd" -FORMAT 1 -TYPE 0 -FILE "' + b + '"'
|
|
|
|
)
|
2012-10-27 23:06:38 +02:00
|
|
|
|
2012-12-10 00:12:07 +01:00
|
|
|
SagaUtils.createSagaBatchJobFileFromSagaCommands(commands)
|
2013-10-01 20:52:22 +03:00
|
|
|
SagaUtils.executeSaga(progress)
|