Skip to content

Commit

Permalink
partially fixed #6571
Browse files Browse the repository at this point in the history
added splitRGBbands algorithm
  • Loading branch information
volaya committed Oct 27, 2012
1 parent 34f677a commit 9587252
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 9 deletions.
5 changes: 4 additions & 1 deletion python/plugins/sextante/core/SextanteUtils.py
Expand Up @@ -65,7 +65,10 @@ def setTempOutput(out, alg):
@staticmethod
def getTempFilename(ext):
path = SextanteUtils.tempFolder()
filename = path + os.sep + str(time.time()) + str(SextanteUtils.getNumExportedLayers()) + "." + ext
if ext is None:
filename = path + os.sep + str(time.time()) + str(SextanteUtils.getNumExportedLayers())
else:
filename = path + os.sep + str(time.time()) + str(SextanteUtils.getNumExportedLayers()) + "." + ext
return filename

@staticmethod
Expand Down
11 changes: 6 additions & 5 deletions python/plugins/sextante/modeler/ModelerParametersDialog.py
Expand Up @@ -16,6 +16,7 @@
* *
***************************************************************************
"""
from sextante.parameters.ParameterCrs import ParameterCrs

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
Expand Down Expand Up @@ -329,15 +330,15 @@ def getTableFields(self):
def getWidgetFromParameter(self, param):
if isinstance(param, ParameterRaster):
item = QtGui.QComboBox()
item.setEditable(True)
#item.setEditable(True)
layers = self.getRasterLayers()
if (param.optional):
item.addItem(self.NOT_SELECTED, None)
for layer in layers:
item.addItem(layer.name(), layer)
elif isinstance(param, ParameterVector):
item = QtGui.QComboBox()
item.setEditable(True)
#item.setEditable(True)
layers = self.getVectorLayers()
if (param.optional):
item.addItem(self.NOT_SELECTED, None)
Expand Down Expand Up @@ -486,8 +487,10 @@ def setPreviousValues(self):
if isinstance(param, (ParameterRaster, ParameterVector,
ParameterTable, ParameterTableField,
ParameterSelection, ParameterNumber,
ParameterString,ParameterBoolean)):
ParameterString,ParameterBoolean, ParameterExtent)):
self.setComboBoxValue(widget, value, param)
elif isinstance(param, ParameterCrs):
widget.setText(unicode(value))
elif isinstance(param, ParameterFixedTable):
pass
elif isinstance(param, ParameterMultipleInput):
Expand Down Expand Up @@ -541,8 +544,6 @@ def setParamValueLayerOrTable(self, param, widget):
self.params[param.name] = value
return True



if widget.currentIndex() < 0:
return False
value = widget.itemData(widget.currentIndex()).toPyObject()
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/sextante/saga/SagaAlgorithm.py
Expand Up @@ -320,7 +320,7 @@ def processAlgorithm(self, progress):


def getOutputCellsize(self):
'''tries to guess the cellsize of the output, searchiing for a parameter with an appropriate name for it'''
'''tries to guess the cellsize of the output, searching for a parameter with an appropriate name for it'''
cellsize = 0;
for param in self.parameters:
if param.value is not None and param.name == "USER_SIZE":
Expand Down
4 changes: 3 additions & 1 deletion python/plugins/sextante/saga/SagaAlgorithmProvider.py
Expand Up @@ -16,6 +16,7 @@
* *
***************************************************************************
"""
from sextante.saga.SplitRGBBands import SplitRGBBands

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
Expand Down Expand Up @@ -80,7 +81,8 @@ def createAlgsList(self):
SextanteLog.addToLog(SextanteLog.LOG_ERROR, "Could not open SAGA algorithm: " + descriptionFile)
except Exception,e:
SextanteLog.addToLog(SextanteLog.LOG_ERROR, "Could not open SAGA algorithm: " + descriptionFile)

self.preloadedAlgs.append(SplitRGBBands())

def _loadAlgorithms(self):
self.algs = self.preloadedAlgs

Expand Down
73 changes: 73 additions & 0 deletions python/plugins/sextante/saga/SplitRGBBands.py
@@ -0,0 +1,73 @@
# -*- 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. *
* *
***************************************************************************
"""
from sextante.core.SextanteUtils import SextanteUtils
from sextante.core.QGisLayers import QGisLayers
from sextante.saga.SagaUtils import SagaUtils

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

from PyQt4 import QtGui
from sextante.core.GeoAlgorithm import GeoAlgorithm
from sextante.parameters.ParameterRaster import ParameterRaster
from sextante.outputs.OutputRaster import OutputRaster
import os

class SplitRGBBands(GeoAlgorithm):

INPUT = "INPUT"
R = "R"
G = "G"
B = "B"

def getIcon(self):
return QtGui.QIcon(os.path.dirname(__file__) + "/../images/saga.png")

def defineCharacteristics(self):
self.name = "Split RGB band"
self.group = "Grid - Tools"
self.addParameter(ParameterRaster(SplitRGBBands.INPUT, "Input layer", False))
self.addOutput(OutputRaster(SplitRGBBands.R, "Output R band layer"))
self.addOutput(OutputRaster(SplitRGBBands.G, "Output G band layer"))
self.addOutput(OutputRaster(SplitRGBBands.B, "Output B band layer"))

def processAlgorithm(self, progress):
#TODO:check correct num of bands
input = self.getParameterValue(SplitRGBBands.INPUT)
temp = SextanteUtils.getTempFilename();
r = self.getOutputValue(SplitRGBBands.R)
g = self.getOutputValue(SplitRGBBands.G)
b = self.getOutputValue(SplitRGBBands.B)
commands = []
if SextanteUtils.isWindows():
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 + "\"");
else:
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 + "\"");

SagaUtils.createSagaBatchJobFileFromSagaCommands(commands)
SagaUtils.executeSaga(progress);
@@ -1,4 +1,4 @@
Split Shapes by Attribute
Split Shapes by Attribute|17
shapes_tools
ParameterVector|TABLE|Table/Shapes|-1|False
ParameterTableField|FIELD|Attribute|TABLE
Expand Down

0 comments on commit 9587252

Please sign in to comment.