Skip to content

Commit

Permalink
fixed bug when running unsaved models
Browse files Browse the repository at this point in the history
added gridmetrics to FUSION

git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@172 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
  • Loading branch information
volayaf committed May 8, 2012
1 parent c80371a commit cd2f975
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/sextante/fusion/FusionAlgorithmProvider.py
Expand Up @@ -11,14 +11,15 @@
from sextante.fusion.ClipData import ClipData
from sextante.fusion.Cover import Cover
from sextante.fusion.FilterData import FilterData
from sextante.fusion.GridMetrics import GridMetrics


class FusionAlgorithmProvider(AlgorithmProvider):

def __init__(self):
AlgorithmProvider.__init__(self)
self.actions.append(OpenViewerAction())
self.algsList = [CloudMetrics(), CanopyMaxima(), CanopyModel(), ClipData(), Cover(), FilterData()]
self.algsList = [CloudMetrics(), CanopyMaxima(), CanopyModel(), ClipData(), Cover(), FilterData(), GridMetrics()]

def initializeSettings(self):
AlgorithmProvider.initializeSettings(self)
Expand Down
41 changes: 41 additions & 0 deletions src/sextante/fusion/GridMetrics.py
@@ -0,0 +1,41 @@
import os
from sextante.parameters.ParameterFile import ParameterFile
from sextante.outputs.OutputTable import OutputTable
from sextante.fusion.FusionUtils import FusionUtils
from sextante.fusion.FusionAlgorithm import FusionAlgorithm
from sextante.parameters.ParameterNumber import ParameterNumber

class GridMetrics(FusionAlgorithm):

INPUT = "INPUT"
OUTPUT = "OUTPUT"
GROUND = "GROUND"
HEIGHT = "HEIGHT"
CELLSIZE = "CELLSIZE"

def defineCharacteristics(self):
self.name = "Grid Metrics"
self.group = "Points"
self.addParameter(ParameterFile(self.INPUT, "Input las layer"))
self.addParameter(ParameterFile(self.GROUND, "Input ground DTM layer"))
self.addParameter(ParameterNumber(self.HEIGHT, "Height break"))
self.addParameter(ParameterNumber(self.CELLSIZE, "Cellsize"))
self.addOutput(OutputTable(self.OUTPUT, "Output table with grid metrics"))
self.addAdvancedModifiers()

def processAlgorithm(self, progress):
commands = [os.path.join(FusionUtils.FusionPath(), "GridMetrics.exe")]
commands.append("/verbose")
self.addAdvancedModifiersToCommand(commands)
commands.append(self.getParameterValue(self.GROUND))
commands.append(str(self.getParameterValue(self.HEIGHT)))
commands.append(str(self.getParameterValue(self.CELLSIZE)))
commands.append(self.getOutputValue(self.OUTPUT))
files = self.getParameterValue(self.INPUT).split(";")
if len(files) == 1:
commands.append(self.getParameterValue(self.INPUT))
else:
FusionUtils.createFileList(files)
commands.append(FusionUtils.tempFileListFilepath())

FusionUtils.runFusion(commands, progress)
4 changes: 4 additions & 0 deletions src/sextante/gui/AlgorithmExecutor.py
Expand Up @@ -5,6 +5,7 @@
from sextante.core.QGisLayers import QGisLayers
from sextante.core.SextanteUtils import SextanteUtils
from sextante.gui.SextantePostprocessing import SextantePostprocessing
import traceback

class AlgorithmExecutor:

Expand All @@ -19,6 +20,9 @@ def runalg(alg, progress):
except GeoAlgorithmExecutionException, e :
QMessageBox.critical(None, "Error", e.msg)
return False
except Exception:
QMessageBox.critical(None, "Error", traceback.format_exc())
return False

@staticmethod
def runalgIterating(alg,paramToIter,progress):
Expand Down
12 changes: 7 additions & 5 deletions src/sextante/modeler/ModelerDialog.py
Expand Up @@ -183,13 +183,15 @@ def runModel(self):
fout.write(text)
fout.close()
self.alg.provider = Providers.providers["model"]
alg = self.alg.getCopy()#copy.deepcopy(self.alg)
alg = self.alg.getCopy()
dlg = ParametersDialog(alg)
dlg.exec_()
self.alg.descriptionFile = None
alg.descriptionFile = None
else:
alg = self.alg.getCopy()#copy.deepcopy(self.alg)
dlg = ParametersDialog(alg)
dlg.exec_()
alg = self.alg.getCopy()
dlg = ParametersDialog(alg)
dlg.exec_()

def saveModel(self):
if str(self.textGroup.text()).strip() == "" or str(self.textName.text()).strip() == "":
Expand All @@ -205,7 +207,7 @@ def saveModel(self):
if filename:
if not filename.endswith(".model"):
filename += ".model"
self.alg.descriptionFile = filename
self.alg.descriptionFile = filename
if filename:
text = self.alg.serialize()
fout = open(filename, "w")
Expand Down
2 changes: 2 additions & 0 deletions src/sextante/r/EditRScriptDialog.py
Expand Up @@ -46,7 +46,9 @@ def saveAlgorithm(self):
filename = self.alg.descriptionFile
else:
filename = QtGui.QFileDialog.getSaveFileName(self, "Save Script", RUtils.RScriptsFolder(), "R-SEXTANTE scripts (*.rsx)")

if filename:
self.alg.descriptionFile = filename
text = self.text.toPlainText()
fout = open(filename, "w")
fout.write(text)
Expand Down
1 change: 1 addition & 0 deletions src/sextante/script/EditScriptDialog.py
Expand Up @@ -59,6 +59,7 @@ def saveAlgorithm(self):
filename = QtGui.QFileDialog.getSaveFileName(self, "Save Script", ScriptUtils.scriptsFolder(), "Python scripts (*.py)")

if filename:
self.alg.descriptionFile = filename
text = self.text.toPlainText()
fout = open(filename, "w")
fout.write(text)
Expand Down

0 comments on commit cd2f975

Please sign in to comment.