Skip to content

Commit

Permalink
Added ParameterFile and OutputFile
Browse files Browse the repository at this point in the history
Added LasTools provider and a few algorithms (still quite a few left, to be added soon)

git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@122 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
  • Loading branch information
volayaf committed Apr 19, 2012
1 parent 97dbc83 commit 6195e81
Show file tree
Hide file tree
Showing 24 changed files with 503 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/sextante/core/LayerExporter.py
Expand Up @@ -46,6 +46,7 @@ def exportVectorLayer(layer):
return str(layer.source())



@staticmethod
def exportRasterLayer(layer):
'''Takes a QgsRasterLayer and returns the filename to refer to it, which allows external
Expand Down
8 changes: 6 additions & 2 deletions src/sextante/core/Sextante.py
Expand Up @@ -19,6 +19,8 @@
from sextante.modeler.ModelerOnlyAlgorithmProvider import ModelerOnlyAlgorithmProvider
from sextante.gdal.GdalAlgorithmProvider import GdalAlgorithmProvider
from sextante.otb.OTBAlgorithmProvider import OTBAlgorithmProvider
from sextante.lastools.LasToolsAlgorithmProvider import LasToolsAlgorithmProvider
from sextante.core.SextanteUtils import SextanteUtils

class Sextante:

Expand Down Expand Up @@ -80,11 +82,13 @@ def initialize():
Sextante.addProvider(MMQGISAlgorithmProvider())
Sextante.addProvider(FToolsAlgorithmProvider())
Sextante.addProvider(ModelerOnlyAlgorithmProvider())
Sextante.addProvider(GdalAlgorithmProvider())
if SextanteUtils.isWindows():
Sextante.addProvider(LasToolsAlgorithmProvider())
Sextante.addProvider(OTBAlgorithmProvider())
Sextante.addProvider(RAlgorithmProvider())
Sextante.addProvider(SagaAlgorithmProvider())
Sextante.addProvider(GrassAlgorithmProvider())
Sextante.addProvider(GdalAlgorithmProvider())
Sextante.addProvider(OTBAlgorithmProvider())
Sextante.addProvider(ScriptAlgorithmProvider())
Sextante.modeler.initializeSettings();
#and initialize
Expand Down
29 changes: 29 additions & 0 deletions src/sextante/gui/FileSelectionPanel.py
@@ -0,0 +1,29 @@
from PyQt4 import QtGui, QtCore
from sextante.core.SextanteUtils import SextanteUtils

class FileSelectionPanel(QtGui.QWidget):

def __init__(self):
super(FileSelectionPanel, self).__init__(None)
self.horizontalLayout = QtGui.QHBoxLayout(self)
self.horizontalLayout.setSpacing(2)
self.horizontalLayout.setMargin(0)
self.text = QtGui.QLineEdit()
self.text.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
self.horizontalLayout.addWidget(self.text)
self.pushButton = QtGui.QPushButton()
self.pushButton.setText("...")
self.pushButton.clicked.connect(self.showSelectionDialog)
self.horizontalLayout.addWidget(self.pushButton)
self.setLayout(self.horizontalLayout)

def showSelectionDialog(self):
filename = QtGui.QFileDialog.getOpenFileName(self, "Open file", QtCore.QString(""), "*.*")
if filename:
self.text.setText(str(filename))

def getValue(self):
s = str(self.text.text())
if SextanteUtils.isWindows():
s = s.replace("/", "\\")
return s
5 changes: 3 additions & 2 deletions src/sextante/gui/ParametersDialog.py
Expand Up @@ -19,6 +19,7 @@
from sextante.parameters.ParameterNumber import ParameterNumber

from sextante.gui.ParametersPanel import ParametersPanel
from sextante.parameters.ParameterFile import ParameterFile

try:
_fromUtf8 = QtCore.QString.fromUtf8
Expand Down Expand Up @@ -123,7 +124,7 @@ def setParamValue(self, param, widget):
for index in widget.selectedoptions:
value.append(options[index])
return param.setValue(value)
elif isinstance(param, ParameterNumber):
elif isinstance(param, (ParameterNumber, ParameterFile)):
return param.setValue(widget.getValue())
else:
return param.setValue(str(widget.text()))
Expand Down Expand Up @@ -153,7 +154,7 @@ def accept(self):
QApplication.restoreOverrideCursor()
if ret:
SextantePostprocessing.handleAlgorithmResults(self.alg)

self.dialog.executed = True
self.dialog.close()

Expand Down
4 changes: 4 additions & 0 deletions src/sextante/gui/ParametersPanel.py
Expand Up @@ -20,6 +20,8 @@
from sextante.gui.ExtentSelectionPanel import ExtentSelectionPanel
from sextante.parameters.ParameterExtent import ParameterExtent
from sextante.core.SextanteConfig import SextanteConfig
from sextante.parameters.ParameterFile import ParameterFile
from sextante.gui.FileSelectionPanel import FileSelectionPanel

class ParametersPanel(QtGui.QWidget):

Expand Down Expand Up @@ -176,6 +178,8 @@ def getWidgetFromParameter(self, param):
item = FixedTablePanel(param)
elif isinstance(param, ParameterRange):
item = RangePanel(param)
elif isinstance(param, ParameterFile):
item = FileSelectionPanel()
elif isinstance(param, ParameterMultipleInput):
if param.datatype == ParameterMultipleInput.TYPE_RASTER:
options = QGisLayers.getRasterLayers()
Expand Down
1 change: 1 addition & 0 deletions src/sextante/gui/SextantePostprocessing.py
Expand Up @@ -9,6 +9,7 @@
from PyQt4.QtGui import *
from sextante.core.SextanteConfig import SextanteConfig
import os
from sextante.outputs.OutputFile import OutputFile
class SextantePostprocessing:

@staticmethod
Expand Down
Binary file added src/sextante/images/tool.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions src/sextante/lastools/LasToolsAlgorithm.py
@@ -0,0 +1,31 @@
from sextante.lastools.LasToolsUtils import LasToolsUtils
from sextante.core.GeoAlgorithm import GeoAlgorithm
from sextante.parameters.ParameterBoolean import ParameterBoolean

class LasToolsAlgorithm(GeoAlgorithm):

FIRST_ONLY = "FIRST_ONLY"
LAST_ONLY = "LAST_ONLY"
SINGLE_RET_ONLY = "SINGLE_RET_ONLY"
DOUBLE_RET_ONLY = "DOUBLE_RET_ONLY"

def checkBeforeOpeningParametersDialog(self):
path = LasToolsUtils.LasToolsPath()
if path == "":
return "SAGA folder is not configured.\nPlease configure it before running SAGA algorithms."

def addCommonParameters(self):
self.addParameter(ParameterBoolean(LasToolsAlgorithm.FIRST_ONLY, "Keep first return only", False))
self.addParameter(ParameterBoolean(LasToolsAlgorithm.LAST_ONLY, "Keep last return only", False))
self.addParameter(ParameterBoolean(LasToolsAlgorithm.SINGLE_RET_ONLY, "Keep single returns only", False))
self.addParameter(ParameterBoolean(LasToolsAlgorithm.DOUBLE_RET_ONLY, "Keep double returns only", False))

def addCommonParameterValuesToCommand(self, commands):
if self.getParameterValue(LasToolsAlgorithm.LAST_ONLY):
commands.append("-last_only")
if self.getParameterValue(LasToolsAlgorithm.FIRST_ONLY):
commands.append("-first_only")
if self.getParameterValue(LasToolsAlgorithm.SINGLE_RET_ONLY):
commands.append("-single_returns_only")
if self.getParameterValue(LasToolsAlgorithm.DOUBLE_RET_ONLY):
commands.append("-double_returns_only")
32 changes: 32 additions & 0 deletions src/sextante/lastools/LasToolsAlgorithmProvider.py
@@ -0,0 +1,32 @@
import os
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from sextante.core.AlgorithmProvider import AlgorithmProvider
from sextante.lastools.LasToolsUtils import LasToolsUtils
from sextante.core.SextanteConfig import Setting, SextanteConfig
from sextante.lastools.las2shp import las2shp
from sextante.lastools.las2dem import las2dem
from sextante.lastools.lasboundary import lasboundary
from sextante.lastools.las2iso import las2iso
from sextante.lastools.lasgrid import lasgrid
from sextante.lastools.lasground import lasground
from sextante.lastools.lasinfo import lasinfo


class LasToolsAlgorithmProvider(AlgorithmProvider):

def __init__(self):
AlgorithmProvider.__init__(self)
self.algsList = [las2shp(), lasboundary(), las2dem(), las2iso(), lasgrid(), lasground(), lasinfo()]

def initializeSettings(self):
AlgorithmProvider.initializeSettings(self)
SextanteConfig.addSetting(Setting("LASTools", LasToolsUtils.LASTOOLS_FOLDER, "LASTools folder", LasToolsUtils.LasToolsPath()))
def getName(self):
return "LASTools"

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

def _loadAlgorithms(self):
self.algs = self.algsList
26 changes: 26 additions & 0 deletions src/sextante/lastools/LasToolsUtils.py
@@ -0,0 +1,26 @@
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import subprocess
from sextante.core.SextanteLog import SextanteLog
from sextante.core.SextanteConfig import SextanteConfig

class LasToolsUtils():

LASTOOLS_FOLDER = "LASTOOLS_FOLDER"

@staticmethod
def LasToolsPath():
folder = SextanteConfig.getSetting(LasToolsUtils.LASTOOLS_FOLDER)
if folder == None:
folder =""

return folder

@staticmethod
def runLasTools(commands, progress):
loglines = []
loglines.append("LasTools execution console output")
proc = subprocess.Popen(commands, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE,stderr=subprocess.STDOUT, universal_newlines=False).stdout
for line in iter(proc.readline, ""):
loglines.append(line)
SextanteLog.addToLog(SextanteLog.LOG_INFO, loglines)
Empty file.
38 changes: 38 additions & 0 deletions src/sextante/lastools/las2dem.py
@@ -0,0 +1,38 @@
import os
from PyQt4 import QtGui
from sextante.parameters.ParameterString import ParameterString
from sextante.lastools.LasToolsUtils import LasToolsUtils
from sextante.parameters.ParameterBoolean import ParameterBoolean
from sextante.outputs.OutputRaster import OutputRaster
from sextante.lastools.LasToolsAlgorithm import LasToolsAlgorithm
from sextante.parameters.ParameterFile import ParameterFile

class las2dem(LasToolsAlgorithm):

INPUT = "INPUT"
OUTPUT = "OUTPUT"
INTENSITY = "INTENSITY"

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

def defineCharacteristics(self):
self.name = "las2dem"
self.group = "Tools"
self.addParameter(ParameterFile(las2dem.INPUT, "Input las layer", ""))
self.addParameter(ParameterBoolean(las2dem.INTENSITY, "Use intensity instead of elevation", False))
self.addOutput(OutputRaster(las2dem.OUTPUT, "Output dem layer"))
self.addCommonParameters()

def processAlgorithm(self, progress):
commands = [os.path.join(LasToolsUtils.LasToolsPath(), "bin", "las2dem.exe")]
commands.append("-i")
commands.append(self.getParameterValue(las2dem.INPUT))
commands.append("-o")
commands.append(self.getOutputValue(las2dem.OUTPUT))
if self.getParameterValue(las2dem.INTENSITY):
commands.append("-intensity")
self.addCommonParameterValuesToCommand(commands)

LasToolsUtils.runLasTools(commands, progress)
51 changes: 51 additions & 0 deletions src/sextante/lastools/las2iso.py
@@ -0,0 +1,51 @@
import os
from PyQt4 import QtGui
from sextante.parameters.ParameterString import ParameterString
from sextante.lastools.LasToolsUtils import LasToolsUtils
from sextante.parameters.ParameterBoolean import ParameterBoolean
from sextante.lastools.LasToolsAlgorithm import LasToolsAlgorithm
from sextante.parameters.ParameterNumber import ParameterNumber
from sextante.outputs.OutputVector import OutputVector
from sextante.parameters.ParameterFile import ParameterFile

class las2iso(LasToolsAlgorithm):

INPUT = "INPUT"
OUTPUT = "OUTPUT"
CLEAN = "CLEAN"
SIMPLIFY = "SIMPLIFY"
INTERVAL = "INTERVAL"

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

def defineCharacteristics(self):
self.name = "las2iso"
self.group = "Tools"
self.addParameter(ParameterFile(las2iso.INPUT, "Input las layer", ""))
self.addParameter(ParameterNumber(las2iso.INTERVAL, "Interval between isolines", 0, None, 10.0))
self.addParameter(ParameterNumber(las2iso.CLEAN, "Clean isolines shorter than (0 = do not clean)", None, None, 0.0))
self.addParameter(ParameterNumber(las2iso.SIMPLIFY, "simplify segments shorter than (0 = do not simplify)", None, None, 0.0))
self.addOutput(OutputVector(las2iso.OUTPUT, "Output isolines"))
self.addCommonParameters()

def processAlgorithm(self, progress):
commands = [os.path.join(LasToolsUtils.LasToolsPath(), "bin", "las2iso.exe")]
commands.append("-i")
commands.append(self.getParameterValue(las2iso.INPUT))
commands.append("-o")
commands.append(self.getOutputValue(las2iso.OUTPUT))
commands.append("-iso_every")
commands.append(str(self.getParameterValue(las2iso.INTERVAL)))
simplify = self.getParameterValue(las2iso.SIMPLIFY)
if simplify != 0:
commands.append("-simplify")
commands.append(str(simplify))
clean = self.getParameterValue(las2iso.CLEAN)
if clean != 0:
commands.append("-clean")
commands.append(str(clean))
self.addCommonParameterValuesToCommand(commands)

LasToolsUtils.runLasTools(commands, progress)
34 changes: 34 additions & 0 deletions src/sextante/lastools/las2shp.py
@@ -0,0 +1,34 @@
import os
from PyQt4 import QtGui
from sextante.parameters.ParameterString import ParameterString
from sextante.outputs.OutputVector import OutputVector
from sextante.lastools.LasToolsUtils import LasToolsUtils
from sextante.lastools.LasToolsAlgorithm import LasToolsAlgorithm
from sextante.parameters.ParameterFile import ParameterFile

class las2shp(LasToolsAlgorithm):

INPUT = "INPUT"
OUTPUT = "OUTPUT"

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

def defineCharacteristics(self):
self.name = "las2shp"
self.group = "Tools"
self.addParameter(ParameterFile(las2shp.INPUT, "Input las layer", ""))
self.addOutput(OutputVector(las2shp.OUTPUT, "Output shp layer"))
self.addCommonParameters()

def processAlgorithm(self, progress):
commands = [os.path.join(LasToolsUtils.LasToolsPath(), "bin", "las2shp.exe")]
commands.append("-i")
commands.append(self.getParameterValue(las2shp.INPUT))
commands.append("-o")
commands.append(self.getOutputValue(las2shp.OUTPUT))
self.addCommonParameterValuesToCommand(commands)


LasToolsUtils.runLasTools(commands, progress)
49 changes: 49 additions & 0 deletions src/sextante/lastools/lasboundary.py
@@ -0,0 +1,49 @@
import os
from PyQt4 import QtGui
from sextante.core.GeoAlgorithm import GeoAlgorithm
from sextante.parameters.ParameterString import ParameterString
from sextante.outputs.OutputVector import OutputVector
from sextante.lastools.LasToolsUtils import LasToolsUtils
from sextante.parameters.ParameterBoolean import ParameterBoolean
from sextante.parameters.ParameterNumber import ParameterNumber
from sextante.lastools.LasToolsAlgorithm import LasToolsAlgorithm
from sextante.parameters.ParameterFile import ParameterFile

class lasboundary(LasToolsAlgorithm):

INPUT = "INPUT"
OUTPUT = "OUTPUT"
CONCAVITY = "CONCAVITY"
DISJOINT = "DISJOINT"
HOLES = "HOLES"


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

def defineCharacteristics(self):
self.name = "lasboundary"
self.group = "Tools"
self.addParameter(ParameterFile(lasboundary.INPUT, "Input las layer", ""))
self.addParameter(ParameterNumber(lasboundary.CONCAVITY, "Concavity threshold", 0, None, 50.0))
self.addParameter(ParameterBoolean(lasboundary.HOLES, "Compute also interior holes", False))
self.addParameter(ParameterBoolean(lasboundary.DISJOINT, "Compute disjoint hull", False))
self.addOutput(OutputVector(lasboundary.OUTPUT, "Output boundary layer"))
self.addCommonParameters()

def processAlgorithm(self, progress):
commands = [os.path.join(LasToolsUtils.LasToolsPath(), "bin", "lasboundary.exe")]
commands.append("-i")
commands.append(self.getParameterValue(lasboundary.INPUT))
commands.append("-o")
commands.append(self.getOutputValue(lasboundary.OUTPUT))
commands.append("-concavity")
commands.append(str(self.getParameterValue(lasboundary.CONCAVITY)))
if self.getParameterValue(lasboundary.HOLES):
commands.append("-holes")
if self.getParameterValue(lasboundary.DISJOINT):
commands.append("-disjoint")
self.addCommonParameterValuesToCommand(commands)

LasToolsUtils.runLasTools(commands, progress)

0 comments on commit 6195e81

Please sign in to comment.