Skip to content

Commit ebf7d1e

Browse files
author
volayaf
committedApr 27, 2012
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
1 parent 4e62f7c commit ebf7d1e

21 files changed

+170
-25
lines changed
 

‎src/sextante/algs/SaveSelectedFeatures.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from PyQt4.QtCore import *
66
from PyQt4.QtGui import *
77
from sextante.core.QGisLayers import QGisLayers
8+
import os
89

910

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

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

4447
def processAlgorithm(self, progress):
4548
'''Here is where the processing itself takes place'''

‎src/sextante/core/GeoAlgorithm.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from sextante.outputs.OutputRaster import OutputRaster
1515
from sextante.outputs.OutputTable import OutputTable
1616
from sextante.outputs.OutputHTML import OutputHTML
17+
import copy
1718

1819
class GeoAlgorithm:
1920

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

3738
self.defineCharacteristics()
3839

40+
def getCopy(self):
41+
newone = copy.copy(self)
42+
newone.parameters = copy.deepcopy(self.parameters)
43+
newone.outputs = copy.deepcopy(self.outputs)
44+
return newone
45+
3946
#methods to overwrite when creating a custom geoalgorithm
4047
#=========================================================
4148
def getIcon(self):

‎src/sextante/core/QGisLayers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ def loadFromDict(layersdict, crs):
114114

115115
@staticmethod
116116
def getObjectFromUri(uri, forceLoad = True):
117+
if uri is None:
118+
return None
117119
layers = QGisLayers.getRasterLayers()
118120
for layer in layers:
119121
if layer.source() == uri:

‎src/sextante/core/Sextante.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from sextante.lastools.LasToolsAlgorithmProvider import LasToolsAlgorithmProvider
2323
from sextante.core.SextanteUtils import SextanteUtils
2424
from sextante.algs.SextanteAlgorithmProvider import SextanteAlgorithmProvider
25+
from sextante.fusion.FusionAlgorithmProvider import FusionAlgorithmProvider
2526

2627
class Sextante:
2728

@@ -87,6 +88,7 @@ def initialize():
8788
Sextante.addProvider(GdalAlgorithmProvider())
8889
if SextanteUtils.isWindows():
8990
Sextante.addProvider(LasToolsAlgorithmProvider())
91+
Sextante.addProvider(FusionAlgorithmProvider())
9092
Sextante.addProvider(OTBAlgorithmProvider())
9193
Sextante.addProvider(RAlgorithmProvider())
9294
Sextante.addProvider(SagaAlgorithmProvider())
@@ -253,7 +255,7 @@ def runalg(name, *args):
253255
Sextante.alghelp(name)
254256
return
255257

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

313-
alg = copy.deepcopy(alg)
315+
alg = alg.getCopy()#copy.deepcopy(alg)
314316
i = 0
315317
for param in alg.parameters:
316318
if not param.setValue(args[i]):

‎src/sextante/fusion/CloudMetrics.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import os
2+
from sextante.parameters.ParameterFile import ParameterFile
3+
from sextante.outputs.OutputTable import OutputTable
4+
from sextante.core.GeoAlgorithm import GeoAlgorithm
5+
from sextante.fusion.FusionUtils import FusionUtils
6+
from PyQt4 import QtGui
7+
8+
class CloudMetrics(GeoAlgorithm):
9+
10+
INPUT = "INPUT"
11+
OUTPUT = "OUTPUT"
12+
13+
def getIcon(self):
14+
return QtGui.QIcon(os.path.dirname(__file__) + "/../images/tool.png")
15+
16+
def defineCharacteristics(self):
17+
self.name = "Cloud Metrics"
18+
self.group = "Tools"
19+
self.addParameter(ParameterFile(self.INPUT, "Input las layer"))
20+
self.addOutput(OutputTable(self.OUTPUT, "Output file with tabular metric information"))
21+
#self.addCommonParameters()
22+
23+
def processAlgorithm(self, progress):
24+
commands = [os.path.join(FusionUtils.FusionPath(), "CloudMetrics.exe")]
25+
files = self.getParameterValue(self.INPUT).split(";")
26+
if len(files) == 1:
27+
commands.append(self.getParameterValue(self.INPUT))
28+
else:
29+
FusionUtils.createFileList(files)
30+
commands.append(FusionUtils.tempFileListFilepath())
31+
commands.append(self.getOutputValue(self.OUTPUT))
32+
#self.addCommonParameterValuesToCommand(commands)
33+
34+
FusionUtils.runFusion(commands, progress)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import os
2+
from PyQt4.QtCore import *
3+
from PyQt4.QtGui import *
4+
from sextante.core.AlgorithmProvider import AlgorithmProvider
5+
from sextante.core.SextanteConfig import Setting, SextanteConfig
6+
from sextante.fusion.FusionUtils import FusionUtils
7+
from sextante.fusion.OpenViewerAction import OpenViewerAction
8+
from sextante.fusion.CloudMetrics import CloudMetrics
9+
10+
11+
class FusionAlgorithmProvider(AlgorithmProvider):
12+
13+
def __init__(self):
14+
AlgorithmProvider.__init__(self)
15+
self.actions.append(OpenViewerAction())
16+
self.algsList = [(CloudMetrics())]
17+
18+
def initializeSettings(self):
19+
AlgorithmProvider.initializeSettings(self)
20+
SextanteConfig.addSetting(Setting(self.getDescription(), FusionUtils.FUSION_FOLDER, "Fusion folder", FusionUtils.FusionPath()))
21+
22+
def getName(self):
23+
return "fusion"
24+
25+
def getDescription(self):
26+
return "FUSION (Tools for LiDAR data)"
27+
28+
def getIcon(self):
29+
return QIcon(os.path.dirname(__file__) + "/../images/tool.png")
30+
31+
def _loadAlgorithms(self):
32+
self.algs = self.algsList
33+
34+
def getSupportedOutputTableExtensions(self):
35+
return ["csv"]

‎src/sextante/fusion/FusionUtils.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from PyQt4.QtCore import *
2+
from PyQt4.QtGui import *
3+
import subprocess
4+
from sextante.core.SextanteLog import SextanteLog
5+
from sextante.core.SextanteConfig import SextanteConfig
6+
import os
7+
from sextante.core.SextanteUtils import SextanteUtils
8+
9+
class FusionUtils():
10+
11+
FUSION_FOLDER = "FUSION_FOLDER"
12+
13+
@staticmethod
14+
def FusionPath():
15+
folder = SextanteConfig.getSetting(FusionUtils.FUSION_FOLDER)
16+
if folder == None:
17+
folder =""
18+
19+
return folder
20+
21+
@staticmethod
22+
def tempFileListFilepath():
23+
filename = "fusion_files_list.txt";
24+
filepath = SextanteUtils.userFolder() + os.sep + filename
25+
return filepath
26+
27+
@staticmethod
28+
def createFileList(files):
29+
out = open(FusionUtils.tempFileListFilepath(), "w")
30+
for f in files:
31+
out.write(f)
32+
out.close()
33+
34+
@staticmethod
35+
def runFusion(commands, progress):
36+
loglines = []
37+
loglines.append("Fusion execution console output")
38+
proc = subprocess.Popen(commands, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE,stderr=subprocess.STDOUT, universal_newlines=False).stdout
39+
for line in iter(proc.readline, ""):
40+
loglines.append(line)
41+
SextanteLog.addToLog(SextanteLog.LOG_INFO, loglines)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from sextante.gui.ToolboxAction import ToolboxAction
2+
import os
3+
from PyQt4 import QtGui
4+
from sextante.fusion.FusionUtils import FusionUtils
5+
import subprocess
6+
7+
class OpenViewerAction(ToolboxAction):
8+
9+
def __init__(self):
10+
self.name="Open LAS viewer"
11+
self.group="Visualization"
12+
13+
def getIcon(self):
14+
return QtGui.QIcon(os.path.dirname(__file__) + "/../images/tool.png")
15+
16+
def execute(self):
17+
f = os.path.join(FusionUtils.FusionPath(), "pdq.exe")
18+
if os.path.exists(f):
19+
subprocess.Popen(f)
20+
else:
21+
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.")

‎src/sextante/fusion/__init__.py

Whitespace-only changes.

‎src/sextante/grass/GrassAlgorithm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def __init__(self, descriptionfile):
3030
self.defineCharacteristicsFromFile()
3131
self.numExportedLayers = 0
3232

33-
def __deepcopy__(self,memo):
33+
def getCopy(self):
3434
newone = GrassAlgorithm(self.descriptionFile)
3535
newone.provider = self.provider
3636
return newone

‎src/sextante/grass/nviz.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from sextante.grass.GrassUtils import GrassUtils
44
from sextante.core.GeoAlgorithm import GeoAlgorithm
55
from PyQt4 import QtGui
6+
from sextante.core.SextanteUtils import SextanteUtils
7+
import time
68

79
class nviz(GeoAlgorithm):
810

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

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

4550
def exportVectorLayer(self,layer):
4651
destFilename = self.getTempFilename()
4752
command = "v.in.ogr"
4853
command += " min_area=-1"
49-
command +=" dsn=\"" + os.path.dirname(filename) + "\""
50-
command +=" layer=" + os.path.basename(filename)[:-4]
54+
command +=" dsn=\"" + os.path.dirname(layer) + "\""
55+
command +=" layer=" + os.path.basename(layer)[:-4]
5156
command +=" output=" + destFilename;
5257
command +=" --overwrite -o"
5358
return destFilename

‎src/sextante/gui/BatchProcessingDialog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def setTableContent(self):
7373
def okPressed(self):
7474
self.algs = []
7575
for row in range(self.table.rowCount()):
76-
alg = copy.deepcopy(self.alg)
76+
alg = self.alg.getCopy()#copy.deepcopy(self.alg)
7777
col = 0
7878
for param in alg.parameters:
7979
widget = self.table.cellWidget(row, col)

‎src/sextante/gui/FileSelectionPanel.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ def showSelectionDialog(self):
2424
if folder:
2525
self.text.setText(str(folder))
2626
else:
27-
filename = QtGui.QFileDialog.getOpenFileName(self, "Open file", QtCore.QString(""), "*.*")
28-
if filename:
29-
self.text.setText(str(filename))
27+
filenames = QtGui.QFileDialog.getOpenFileNames(self, "Open file", QtCore.QString(""), "*.*")
28+
if filenames:
29+
self.text.setText(str(filenames.join(";")))
3030

3131
def getValue(self):
3232
s = str(self.text.text())

‎src/sextante/gui/SextanteToolbox.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def executeAlgorithm(self):
9898
if message:
9999
QtGui.QMessageBox.warning(self, "Warning", message)
100100
return
101-
alg = copy.deepcopy(alg)
101+
alg = alg.getCopy()#copy.deepcopy(alg)
102102
dlg = alg.getCustomParametersDialog()
103103
if not dlg:
104104
dlg = ParametersDialog(alg)
@@ -175,7 +175,6 @@ def fillTree(self):
175175
if len(recent) != 0:
176176
recentItem = QtGui.QTreeWidgetItem()
177177
recentItem.setText(0,"Recently used algorithms")
178-
#providerItem.setIcon(0, Sextante.getProviderFromName(providerName).getIcon())
179178
for algname in recent:
180179
alg = Sextante.getAlgorithm(algname)
181180
algItem = TreeAlgorithmItem(alg)

‎src/sextante/lastools/las2iso.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import os
2-
from PyQt4 import QtGui
3-
from sextante.parameters.ParameterString import ParameterString
42
from sextante.lastools.LasToolsUtils import LasToolsUtils
5-
from sextante.parameters.ParameterBoolean import ParameterBoolean
63
from sextante.lastools.LasToolsAlgorithm import LasToolsAlgorithm
74
from sextante.parameters.ParameterNumber import ParameterNumber
85
from sextante.outputs.OutputVector import OutputVector

‎src/sextante/modeler/ModelerAlgorithm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
class ModelerAlgorithm(GeoAlgorithm):
2020

21-
def __deepcopy__(self,memo):
21+
def getCopy(self):
2222
newone = ModelerAlgorithm()
2323
newone.openModel(self.descriptionFile)
2424
newone.provider = self.provider
@@ -234,7 +234,7 @@ def processAlgorithm(self, progress):
234234
iAlg = 0
235235
for alg in self.algs:
236236
try:
237-
alg = copy.deepcopy(alg)
237+
alg = alg.getCopy()#copy.deepcopy(alg)
238238
self.prepareAlgorithm(alg, iAlg)
239239
progress.setText("Running " + alg.name + " [" + str(iAlg+1) + "/" + str(len(self.algs)) +"]")
240240
outputs = {}

‎src/sextante/modeler/ModelerDialog.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,12 @@ def runModel(self):
182182
fout = open(self.alg.descriptionFile, "w")
183183
fout.write(text)
184184
fout.close()
185-
self.alg.provider = Providers.providers["Modeler"]
186-
alg = copy.deepcopy(self.alg)
185+
self.alg.provider = Providers.providers["model"]
186+
alg = self.alg.getCopy()#copy.deepcopy(self.alg)
187187
self.alg.descriptionFile = None
188188
alg.descriptionFile = None
189189
else:
190-
alg = copy.deepcopy(self.alg)
190+
alg = self.alg.getCopy()#copy.deepcopy(self.alg)
191191
dlg = ParametersDialog(alg)
192192
dlg.exec_()
193193

@@ -272,7 +272,7 @@ def addAlgorithm(self):
272272
item = self.algorithmTree.currentItem()
273273
if isinstance(item, TreeAlgorithmItem):
274274
alg = ModelerUtils.getAlgorithm(item.alg.commandLineName())
275-
alg = copy.deepcopy(alg)
275+
alg = alg.getCopy()#copy.deepcopy(alg)
276276
dlg = alg.getCustomModelerParametersDialog(self.alg)
277277
if not dlg:
278278
dlg = ModelerParametersDialog(alg, self.alg)

‎src/sextante/otb/OTBAlgorithm.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from sextante.core.SextanteLog import SextanteLog
1515
from sextante.parameters.ParameterFactory import ParameterFactory
1616
from sextante.outputs.OutputFactory import OutputFactory
17-
from sextante.core.SextanteUtils import SextanteUtils
1817
from sextante.otb.OTBUtils import OTBUtils
1918

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

28-
def __deepcopy__(self,memo):
27+
def getCopy(self):
2928
newone = OTBAlgorithm(self.descriptionFile)
3029
newone.provider = self.provider
3130
return newone

‎src/sextante/r/RAlgorithm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class RAlgorithm(GeoAlgorithm):
3131
R_CONSOLE_OUTPUT = "R_CONSOLE_OUTPUT"
3232
RPLOTS = "RPLOTS"
3333

34-
def __deepcopy__(self,memo):
34+
def getCopy(self):
3535
newone = RAlgorithm(self.descriptionFile)
3636
newone.provider = self.provider
3737
return newone

‎src/sextante/saga/SagaAlgorithm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def __init__(self, descriptionfile):
4040
#reconsider resampling policy now that we know the input parameters
4141
self.resample = self.setResamplingPolicy()
4242

43-
def __deepcopy__(self,memo):
43+
def getCopy(self):
4444
newone = SagaAlgorithm(self.descriptionFile)
4545
newone.provider = self.provider
4646
return newone

‎src/sextante/script/ScriptAlgorithm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def __init__(self, descriptionfile):
2727
self.descriptionFile = descriptionfile
2828
self.defineCharacteristicsFromFile()
2929

30-
def __deepcopy__(self,memo):
30+
def getCopy(self):
3131
newone = ScriptAlgorithm(self.descriptionFile)
3232
newone.provider = self.provider
3333
return newone

0 commit comments

Comments
 (0)
Please sign in to comment.