Skip to content

Commit

Permalink
added grass region definition from layer
Browse files Browse the repository at this point in the history
fixed problem with grass algorithms requiring an explicit region

git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@311 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
  • Loading branch information
volayaf committed Jul 26, 2012
1 parent 488c939 commit f3f81d5
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 23 deletions.
33 changes: 33 additions & 0 deletions src/sextante/grass/DefineGrassRegionFromLayerAction.py
@@ -0,0 +1,33 @@
import os
from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from sextante.gui.ToolboxAction import ToolboxAction
from sextante.core.QGisLayers import QGisLayers
from sextante.core.SextanteConfig import SextanteConfig
from sextante.grass.GrassUtils import GrassUtils

class DefineGrassRegionFromLayerAction(ToolboxAction):

def __init__(self):
self.name="Define GRASS region from layer"
self.group="Tools"

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

def execute(self):
layers = QGisLayers.getAllLayers();
layersMap = {layer.name() : layer for layer in layers}
layerNames = [layer.name() for layer in layers]
item, ok = QtGui.QInputDialog.getItem(None, "Select a layer", "Layer selection", layerNames, editable=False)
if ok:
layer = layersMap[item]
SextanteConfig.setSettingValue(GrassUtils.GRASS_REGION_XMIN, layer.extent().xMinimum())
SextanteConfig.setSettingValue(GrassUtils.GRASS_REGION_YMIN, layer.extent().yMinimum())
SextanteConfig.setSettingValue(GrassUtils.GRASS_REGION_XMAX, layer.extent().xMaximum())
SextanteConfig.setSettingValue(GrassUtils.GRASS_REGION_YMAX, layer.extent().yMaximum())
SextanteConfig.setSettingValue(GrassUtils.GRASS_AUTO_REGION, False)
s = str(layer.extent().xMinimum()) + "," + str(layer.extent().xMaximum()) + "," + str(layer.extent().yMinimum()) + "," + str(layer.extent().yMaximum())
QtGui.QMessageBox.information(None, "GRASS Region", "GRASS region set to:\n" + s + \
"\nTo set the cellsize or set back the autoregion option,\ngo to the SEXTANTE configuration.")
13 changes: 13 additions & 0 deletions src/sextante/grass/GrassAlgorithm.py
Expand Up @@ -305,3 +305,16 @@ def getTempFilename(self):

def commandLineName(self):
return "grass:" + self.name[:self.name.find(" ")]

def checkBeforeOpeningParametersDialog(self):
for param in self.parameters:
if isinstance(param, (ParameterRaster, ParameterVector)):
return None
if isinstance(param, ParameterMultipleInput):
if not param.optional:
return None

if SextanteConfig.getSetting(GrassUtils.GRASS_AUTO_REGION):
return "This algorithm cannot be run with the 'auto-region' setting\nPlease set a GRASS region before running it"
else:
return None
2 changes: 2 additions & 0 deletions src/sextante/grass/GrassAlgorithmProvider.py
Expand Up @@ -8,12 +8,14 @@
from sextante.grass.GrassAlgorithm import GrassAlgorithm
from sextante.core.SextanteUtils import SextanteUtils
from sextante.grass.DefineGrassRegionAction import DefineGrassRegionAction
from sextante.grass.DefineGrassRegionFromLayerAction import DefineGrassRegionFromLayerAction

class GrassAlgorithmProvider(AlgorithmProvider):

def __init__(self):
AlgorithmProvider.__init__(self)
self.actions.append(DefineGrassRegionAction())
self.actions.append(DefineGrassRegionFromLayerAction())
self.createAlgsList() #preloading algorithms to speed up

def initializeSettings(self):
Expand Down
21 changes: 0 additions & 21 deletions src/sextante/grass/description/v.vol.rst.txt

This file was deleted.

2 changes: 0 additions & 2 deletions src/sextante/modeler/ModelerDialog.py
Expand Up @@ -7,9 +7,7 @@
from sextante.modeler.ModelerUtils import ModelerUtils
from sextante.modeler.WrongModelException import WrongModelException
from sextante.modeler.ModelerScene import ModelerScene
import copy
from sextante.modeler.Providers import Providers
from sextante.script.ScriptUtils import ScriptUtils
from sextante.gui.HelpEditionDialog import HelpEditionDialog
import pickle
from sextante.gui.ParametersDialog import ParametersDialog
Expand Down
2 changes: 2 additions & 0 deletions src/sextante/outputs/Output.py
Expand Up @@ -5,6 +5,8 @@ class Output(object):
def __init__(self, name="", description="", hidden=False):
self.name = name
self.description = description
#the value of an output is a string representing the location of the output.
#For a file based output, it should be the filepath to it.
self.value = None
# a hidden output will not be shown to the user, who will not be able to select where to store it
# Use this to generate outputs that are modified version of inputs (like a selection in a vector layer)
Expand Down

0 comments on commit f3f81d5

Please sign in to comment.