Skip to content
Permalink
Browse files
changed copy method for algorithms
fixed #5450
started added FUSION lidar tools

git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@159 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
  • Loading branch information
volayaf committed Apr 27, 2012
1 parent 4e62f7c commit ebf7d1e598d9bc8c26c5ab6a3b042fe37dfa107e
@@ -5,6 +5,7 @@
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from sextante.core.QGisLayers import QGisLayers
import os


class SaveSelectedFeatures(GeoAlgorithm):
@@ -40,6 +41,8 @@ def defineCharacteristics(self):
# we add a vector layer as output
self.addOutput(OutputVector(self.OUTPUT_LAYER, "Output layer with selected features"))

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

def processAlgorithm(self, progress):
'''Here is where the processing itself takes place'''
@@ -14,6 +14,7 @@
from sextante.outputs.OutputRaster import OutputRaster
from sextante.outputs.OutputTable import OutputTable
from sextante.outputs.OutputHTML import OutputHTML
import copy

class GeoAlgorithm:

@@ -36,6 +37,12 @@ def __init__(self):

self.defineCharacteristics()

def getCopy(self):
newone = copy.copy(self)
newone.parameters = copy.deepcopy(self.parameters)
newone.outputs = copy.deepcopy(self.outputs)
return newone

#methods to overwrite when creating a custom geoalgorithm
#=========================================================
def getIcon(self):
@@ -114,6 +114,8 @@ def loadFromDict(layersdict, crs):

@staticmethod
def getObjectFromUri(uri, forceLoad = True):
if uri is None:
return None
layers = QGisLayers.getRasterLayers()
for layer in layers:
if layer.source() == uri:
@@ -22,6 +22,7 @@
from sextante.lastools.LasToolsAlgorithmProvider import LasToolsAlgorithmProvider
from sextante.core.SextanteUtils import SextanteUtils
from sextante.algs.SextanteAlgorithmProvider import SextanteAlgorithmProvider
from sextante.fusion.FusionAlgorithmProvider import FusionAlgorithmProvider

class Sextante:

@@ -87,6 +88,7 @@ def initialize():
Sextante.addProvider(GdalAlgorithmProvider())
if SextanteUtils.isWindows():
Sextante.addProvider(LasToolsAlgorithmProvider())
Sextante.addProvider(FusionAlgorithmProvider())
Sextante.addProvider(OTBAlgorithmProvider())
Sextante.addProvider(RAlgorithmProvider())
Sextante.addProvider(SagaAlgorithmProvider())
@@ -253,7 +255,7 @@ def runalg(name, *args):
Sextante.alghelp(name)
return

alg = copy.deepcopy(alg)
alg = alg.getCopy()#copy.deepcopy(alg)
i = 0
for param in alg.parameters:
if not param.setValue(args[i]):
@@ -310,7 +312,7 @@ def runandload(name, *args):
Sextante.alghelp(name)
return

alg = copy.deepcopy(alg)
alg = alg.getCopy()#copy.deepcopy(alg)
i = 0
for param in alg.parameters:
if not param.setValue(args[i]):
@@ -0,0 +1,34 @@
import os
from sextante.parameters.ParameterFile import ParameterFile
from sextante.outputs.OutputTable import OutputTable
from sextante.core.GeoAlgorithm import GeoAlgorithm
from sextante.fusion.FusionUtils import FusionUtils
from PyQt4 import QtGui

class CloudMetrics(GeoAlgorithm):

INPUT = "INPUT"
OUTPUT = "OUTPUT"

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

def defineCharacteristics(self):
self.name = "Cloud Metrics"
self.group = "Tools"
self.addParameter(ParameterFile(self.INPUT, "Input las layer"))
self.addOutput(OutputTable(self.OUTPUT, "Output file with tabular metric information"))
#self.addCommonParameters()

def processAlgorithm(self, progress):
commands = [os.path.join(FusionUtils.FusionPath(), "CloudMetrics.exe")]
files = self.getParameterValue(self.INPUT).split(";")
if len(files) == 1:
commands.append(self.getParameterValue(self.INPUT))
else:
FusionUtils.createFileList(files)
commands.append(FusionUtils.tempFileListFilepath())
commands.append(self.getOutputValue(self.OUTPUT))
#self.addCommonParameterValuesToCommand(commands)

FusionUtils.runFusion(commands, progress)
@@ -0,0 +1,35 @@
import os
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from sextante.core.AlgorithmProvider import AlgorithmProvider
from sextante.core.SextanteConfig import Setting, SextanteConfig
from sextante.fusion.FusionUtils import FusionUtils
from sextante.fusion.OpenViewerAction import OpenViewerAction
from sextante.fusion.CloudMetrics import CloudMetrics


class FusionAlgorithmProvider(AlgorithmProvider):

def __init__(self):
AlgorithmProvider.__init__(self)
self.actions.append(OpenViewerAction())
self.algsList = [(CloudMetrics())]

def initializeSettings(self):
AlgorithmProvider.initializeSettings(self)
SextanteConfig.addSetting(Setting(self.getDescription(), FusionUtils.FUSION_FOLDER, "Fusion folder", FusionUtils.FusionPath()))

def getName(self):
return "fusion"

def getDescription(self):
return "FUSION (Tools for LiDAR data)"

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

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

def getSupportedOutputTableExtensions(self):
return ["csv"]
@@ -0,0 +1,41 @@
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import subprocess
from sextante.core.SextanteLog import SextanteLog
from sextante.core.SextanteConfig import SextanteConfig
import os
from sextante.core.SextanteUtils import SextanteUtils

class FusionUtils():

FUSION_FOLDER = "FUSION_FOLDER"

@staticmethod
def FusionPath():
folder = SextanteConfig.getSetting(FusionUtils.FUSION_FOLDER)
if folder == None:
folder =""

return folder

@staticmethod
def tempFileListFilepath():
filename = "fusion_files_list.txt";
filepath = SextanteUtils.userFolder() + os.sep + filename
return filepath

@staticmethod
def createFileList(files):
out = open(FusionUtils.tempFileListFilepath(), "w")
for f in files:
out.write(f)
out.close()

@staticmethod
def runFusion(commands, progress):
loglines = []
loglines.append("Fusion 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)
@@ -0,0 +1,21 @@
from sextante.gui.ToolboxAction import ToolboxAction
import os
from PyQt4 import QtGui
from sextante.fusion.FusionUtils import FusionUtils
import subprocess

class OpenViewerAction(ToolboxAction):

def __init__(self):
self.name="Open LAS viewer"
self.group="Visualization"

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

def execute(self):
f = os.path.join(FusionUtils.FusionPath(), "pdq.exe")
if os.path.exists(f):
subprocess.Popen(f)
else:
QtGui.QMessageBox.critical(None, "Unable to open viewer", "The current Fusion folder does not contain the viewer executable.\nPlease check the configuration in the SEXTANTE settings dialog.")
Empty file.
@@ -30,7 +30,7 @@ def __init__(self, descriptionfile):
self.defineCharacteristicsFromFile()
self.numExportedLayers = 0

def __deepcopy__(self,memo):
def getCopy(self):
newone = GrassAlgorithm(self.descriptionFile)
newone.provider = self.provider
return newone
@@ -3,6 +3,8 @@
from sextante.grass.GrassUtils import GrassUtils
from sextante.core.GeoAlgorithm import GeoAlgorithm
from PyQt4 import QtGui
from sextante.core.SextanteUtils import SextanteUtils
import time

class nviz(GeoAlgorithm):

@@ -41,13 +43,16 @@ def processAlgorithm(self, progress):
GrassUtils.createTempMapset();
GrassUtils.executeGrass(commands, progress)

def getTempFilename(self):
filename = "tmp" + str(time.time()).replace(".","") + str(SextanteUtils.getNumExportedLayers())
return filename

def exportVectorLayer(self,layer):
destFilename = self.getTempFilename()
command = "v.in.ogr"
command += " min_area=-1"
command +=" dsn=\"" + os.path.dirname(filename) + "\""
command +=" layer=" + os.path.basename(filename)[:-4]
command +=" dsn=\"" + os.path.dirname(layer) + "\""
command +=" layer=" + os.path.basename(layer)[:-4]
command +=" output=" + destFilename;
command +=" --overwrite -o"
return destFilename
@@ -73,7 +73,7 @@ def setTableContent(self):
def okPressed(self):
self.algs = []
for row in range(self.table.rowCount()):
alg = copy.deepcopy(self.alg)
alg = self.alg.getCopy()#copy.deepcopy(self.alg)
col = 0
for param in alg.parameters:
widget = self.table.cellWidget(row, col)
@@ -24,9 +24,9 @@ def showSelectionDialog(self):
if folder:
self.text.setText(str(folder))
else:
filename = QtGui.QFileDialog.getOpenFileName(self, "Open file", QtCore.QString(""), "*.*")
if filename:
self.text.setText(str(filename))
filenames = QtGui.QFileDialog.getOpenFileNames(self, "Open file", QtCore.QString(""), "*.*")
if filenames:
self.text.setText(str(filenames.join(";")))

def getValue(self):
s = str(self.text.text())
@@ -98,7 +98,7 @@ def executeAlgorithm(self):
if message:
QtGui.QMessageBox.warning(self, "Warning", message)
return
alg = copy.deepcopy(alg)
alg = alg.getCopy()#copy.deepcopy(alg)
dlg = alg.getCustomParametersDialog()
if not dlg:
dlg = ParametersDialog(alg)
@@ -175,7 +175,6 @@ def fillTree(self):
if len(recent) != 0:
recentItem = QtGui.QTreeWidgetItem()
recentItem.setText(0,"Recently used algorithms")
#providerItem.setIcon(0, Sextante.getProviderFromName(providerName).getIcon())
for algname in recent:
alg = Sextante.getAlgorithm(algname)
algItem = TreeAlgorithmItem(alg)
@@ -1,8 +1,5 @@
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
@@ -18,7 +18,7 @@

class ModelerAlgorithm(GeoAlgorithm):

def __deepcopy__(self,memo):
def getCopy(self):
newone = ModelerAlgorithm()
newone.openModel(self.descriptionFile)
newone.provider = self.provider
@@ -234,7 +234,7 @@ def processAlgorithm(self, progress):
iAlg = 0
for alg in self.algs:
try:
alg = copy.deepcopy(alg)
alg = alg.getCopy()#copy.deepcopy(alg)
self.prepareAlgorithm(alg, iAlg)
progress.setText("Running " + alg.name + " [" + str(iAlg+1) + "/" + str(len(self.algs)) +"]")
outputs = {}
@@ -182,12 +182,12 @@ def runModel(self):
fout = open(self.alg.descriptionFile, "w")
fout.write(text)
fout.close()
self.alg.provider = Providers.providers["Modeler"]
alg = copy.deepcopy(self.alg)
self.alg.provider = Providers.providers["model"]
alg = self.alg.getCopy()#copy.deepcopy(self.alg)
self.alg.descriptionFile = None
alg.descriptionFile = None
else:
alg = copy.deepcopy(self.alg)
alg = self.alg.getCopy()#copy.deepcopy(self.alg)
dlg = ParametersDialog(alg)
dlg.exec_()

@@ -272,7 +272,7 @@ def addAlgorithm(self):
item = self.algorithmTree.currentItem()
if isinstance(item, TreeAlgorithmItem):
alg = ModelerUtils.getAlgorithm(item.alg.commandLineName())
alg = copy.deepcopy(alg)
alg = alg.getCopy()#copy.deepcopy(alg)
dlg = alg.getCustomModelerParametersDialog(self.alg)
if not dlg:
dlg = ModelerParametersDialog(alg, self.alg)
@@ -14,7 +14,6 @@
from sextante.core.SextanteLog import SextanteLog
from sextante.parameters.ParameterFactory import ParameterFactory
from sextante.outputs.OutputFactory import OutputFactory
from sextante.core.SextanteUtils import SextanteUtils
from sextante.otb.OTBUtils import OTBUtils

class OTBAlgorithm(GeoAlgorithm):
@@ -25,7 +24,7 @@ def __init__(self, descriptionfile):
self.defineCharacteristicsFromFile()
self.numExportedLayers = 0

def __deepcopy__(self,memo):
def getCopy(self):
newone = OTBAlgorithm(self.descriptionFile)
newone.provider = self.provider
return newone
@@ -31,7 +31,7 @@ class RAlgorithm(GeoAlgorithm):
R_CONSOLE_OUTPUT = "R_CONSOLE_OUTPUT"
RPLOTS = "RPLOTS"

def __deepcopy__(self,memo):
def getCopy(self):
newone = RAlgorithm(self.descriptionFile)
newone.provider = self.provider
return newone
@@ -40,7 +40,7 @@ def __init__(self, descriptionfile):
#reconsider resampling policy now that we know the input parameters
self.resample = self.setResamplingPolicy()

def __deepcopy__(self,memo):
def getCopy(self):
newone = SagaAlgorithm(self.descriptionFile)
newone.provider = self.provider
return newone
@@ -27,7 +27,7 @@ def __init__(self, descriptionfile):
self.descriptionFile = descriptionfile
self.defineCharacteristicsFromFile()

def __deepcopy__(self,memo):
def getCopy(self):
newone = ScriptAlgorithm(self.descriptionFile)
newone.provider = self.provider
return newone

0 comments on commit ebf7d1e

Please sign in to comment.