Skip to content

Commit f3f81d5

Browse files
author
volayaf
committedJul 26, 2012
added grass region definition from layer
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
1 parent 488c939 commit f3f81d5

File tree

6 files changed

+50
-23
lines changed

6 files changed

+50
-23
lines changed
 
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import os
2+
from PyQt4 import QtGui, QtCore
3+
from PyQt4.QtCore import *
4+
from PyQt4.QtGui import *
5+
from sextante.gui.ToolboxAction import ToolboxAction
6+
from sextante.core.QGisLayers import QGisLayers
7+
from sextante.core.SextanteConfig import SextanteConfig
8+
from sextante.grass.GrassUtils import GrassUtils
9+
10+
class DefineGrassRegionFromLayerAction(ToolboxAction):
11+
12+
def __init__(self):
13+
self.name="Define GRASS region from layer"
14+
self.group="Tools"
15+
16+
def getIcon(self):
17+
return QtGui.QIcon(os.path.dirname(__file__) + "/../images/grass.png")
18+
19+
def execute(self):
20+
layers = QGisLayers.getAllLayers();
21+
layersMap = {layer.name() : layer for layer in layers}
22+
layerNames = [layer.name() for layer in layers]
23+
item, ok = QtGui.QInputDialog.getItem(None, "Select a layer", "Layer selection", layerNames, editable=False)
24+
if ok:
25+
layer = layersMap[item]
26+
SextanteConfig.setSettingValue(GrassUtils.GRASS_REGION_XMIN, layer.extent().xMinimum())
27+
SextanteConfig.setSettingValue(GrassUtils.GRASS_REGION_YMIN, layer.extent().yMinimum())
28+
SextanteConfig.setSettingValue(GrassUtils.GRASS_REGION_XMAX, layer.extent().xMaximum())
29+
SextanteConfig.setSettingValue(GrassUtils.GRASS_REGION_YMAX, layer.extent().yMaximum())
30+
SextanteConfig.setSettingValue(GrassUtils.GRASS_AUTO_REGION, False)
31+
s = str(layer.extent().xMinimum()) + "," + str(layer.extent().xMaximum()) + "," + str(layer.extent().yMinimum()) + "," + str(layer.extent().yMaximum())
32+
QtGui.QMessageBox.information(None, "GRASS Region", "GRASS region set to:\n" + s + \
33+
"\nTo set the cellsize or set back the autoregion option,\ngo to the SEXTANTE configuration.")

‎src/sextante/grass/GrassAlgorithm.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,3 +305,16 @@ def getTempFilename(self):
305305

306306
def commandLineName(self):
307307
return "grass:" + self.name[:self.name.find(" ")]
308+
309+
def checkBeforeOpeningParametersDialog(self):
310+
for param in self.parameters:
311+
if isinstance(param, (ParameterRaster, ParameterVector)):
312+
return None
313+
if isinstance(param, ParameterMultipleInput):
314+
if not param.optional:
315+
return None
316+
317+
if SextanteConfig.getSetting(GrassUtils.GRASS_AUTO_REGION):
318+
return "This algorithm cannot be run with the 'auto-region' setting\nPlease set a GRASS region before running it"
319+
else:
320+
return None

‎src/sextante/grass/GrassAlgorithmProvider.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
from sextante.grass.GrassAlgorithm import GrassAlgorithm
99
from sextante.core.SextanteUtils import SextanteUtils
1010
from sextante.grass.DefineGrassRegionAction import DefineGrassRegionAction
11+
from sextante.grass.DefineGrassRegionFromLayerAction import DefineGrassRegionFromLayerAction
1112

1213
class GrassAlgorithmProvider(AlgorithmProvider):
1314

1415
def __init__(self):
1516
AlgorithmProvider.__init__(self)
1617
self.actions.append(DefineGrassRegionAction())
18+
self.actions.append(DefineGrassRegionFromLayerAction())
1719
self.createAlgsList() #preloading algorithms to speed up
1820

1921
def initializeSettings(self):

‎src/sextante/grass/description/v.vol.rst.txt

Lines changed: 0 additions & 21 deletions
This file was deleted.

‎src/sextante/modeler/ModelerDialog.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
from sextante.modeler.ModelerUtils import ModelerUtils
88
from sextante.modeler.WrongModelException import WrongModelException
99
from sextante.modeler.ModelerScene import ModelerScene
10-
import copy
1110
from sextante.modeler.Providers import Providers
12-
from sextante.script.ScriptUtils import ScriptUtils
1311
from sextante.gui.HelpEditionDialog import HelpEditionDialog
1412
import pickle
1513
from sextante.gui.ParametersDialog import ParametersDialog

‎src/sextante/outputs/Output.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ class Output(object):
55
def __init__(self, name="", description="", hidden=False):
66
self.name = name
77
self.description = description
8+
#the value of an output is a string representing the location of the output.
9+
#For a file based output, it should be the filepath to it.
810
self.value = None
911
# a hidden output will not be shown to the user, who will not be able to select where to store it
1012
# Use this to generate outputs that are modified version of inputs (like a selection in a vector layer)

0 commit comments

Comments
 (0)
Please sign in to comment.