3 changes: 2 additions & 1 deletion python/plugins/sextante/algs/ftools/Buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@
* *
***************************************************************************
"""
from sextante.core.QGisLayers import QGisLayers

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'


from PyQt4.QtCore import *

from qgis.core import *

from sextante.core.QGisLayers import QGisLayers
from sextante.core.SextanteLog import SextanteLog

def buffering(progress, writer, distance, field, useField, layer, dissolve, segments):
Expand Down
7 changes: 4 additions & 3 deletions python/plugins/sextante/algs/ftools/Intersection.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ def processAlgorithm(self, progress):
geom = QgsGeometry( inFeatA.geometry() )
atMapA = inFeatA.attributes()
intersects = index.intersects( geom.boundingBox() )
for id in intersects:
vlayerB.featureAtId( int( id ), inFeatB , True)
tmpGeom = QgsGeometry( inFeatB.geometry() )
for i in intersects:
request = QgsFeatureRequest().setFilterFid(i)
inFeatB = vlayerB.getFeatures(request).next()
tmpGeom = QgsGeometry(inFeatB.geometry())
try:
if geom.intersects( tmpGeom ):
atMapB = inFeatB.attributes()
Expand Down
6 changes: 4 additions & 2 deletions python/plugins/sextante/algs/ftools/Union.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ def processAlgorithm(self, progress):
else:
for id in intersects:
count += 1
vlayerB.featureAtId( int( id ), inFeatB , True)
request = QgsFeatureRequest().setFilterFid(id)
inFeatB = vlayerB.getFeatures(request).next()
atMapB = inFeatB.attributes()
tmpGeom = QgsGeometry( inFeatB.geometry() )

Expand Down Expand Up @@ -171,7 +172,8 @@ def processAlgorithm(self, progress):
raise GeoAlgorithmExecutionException("Feature exception while computing union")
else:
for id in intersects:
vlayerA.featureAtId( int( id ), inFeatB , True)
request = QgsFeatureRequest().setFilterFid(id)
inFeatB = vlayerA.getFeatures(request).next()
atMapB = inFeatB.attributes()
tmpGeom = QgsGeometry( inFeatB.geometry() )
try:
Expand Down
4 changes: 3 additions & 1 deletion python/plugins/sextante/core/LayerExporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* *
***************************************************************************
"""
import os.path

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
Expand Down Expand Up @@ -48,7 +49,8 @@ def exportVectorLayer(layer):
It also export to a new file if the original one contains non-ascii characters'''
settings = QSettings()
systemEncoding = settings.value( "/UI/encoding", "System" ).toString()
output = SextanteUtils.getTempFilename("shp")
output = SextanteUtils.getTempFilenameInTempFolder(os.path.basename(unicode(layer.source())) + ".shp")
#output = SextanteUtils.getTempFilename("shp")
provider = layer.dataProvider()
useSelection = SextanteConfig.getSetting(SextanteConfig.USE_SELECTED)
if useSelection and layer.selectedFeatureCount() != 0:
Expand Down
11 changes: 10 additions & 1 deletion python/plugins/sextante/core/SextanteUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def setTempOutput(out, alg):
ext = out.getDefaultFileExtension(alg)
validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
safeCmdName = ''.join(c for c in alg.commandLineName() if c in validChars)
uniqueSufix = str(uuid.uuid4()).replace("-","");
uniqueSufix = str(uuid.uuid4()).replace("-","")
filename = SextanteUtils.tempFolder() + os.sep + safeCmdName + uniqueSufix + "." + ext
out.value = filename

Expand All @@ -76,6 +76,15 @@ def getTempFilename(ext):
filename = path + os.sep + str(time.time()) + str(SextanteUtils.getNumExportedLayers()) + "." + ext
return filename

@staticmethod
def getTempFilenameInTempFolder(basename):
'''returns a temporary filename for a given file, putting it into a temp folder but not changing its basename'''
path = SextanteUtils.tempFolder()
tempFolder = os.path.join(path, str(uuid.uuid4()).replace("-",""))
mkdir(tempFolder)
filename = os.path.join(tempFolder, basename)
return filename

@staticmethod
def getNumExportedLayers():
SextanteUtils.NUM_EXPORTED += 1
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/sextante/gui/AlgorithmExecutionDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def accept(self):
palette = ex.widget.palette()
palette.setColor(QPalette.Base, QColor(255, 255, 0))
ex.widget.setPalette(palette)
self.progressLabel.setText("<b>Missing parameter value</b>")
self.progressLabel.setText("<b>Missing parameter value: " + ex.parameter.description + "</b>")
return
except:
QMessageBox.critical(self, "Unable to execute algorithm", "Wrong or missing parameter values")
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/sextante/gui/BatchInputSelectionPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ def showSelectionDialog(self):
elif os.path.isdir(os.path.dirname(text)):
path = os.path.dirname(text)
elif settings.contains("/SextanteQGIS/LastInputPath"):
path = str(settings.value( "/SextanteQGIS/LastInputPath",QtCore.QVariant( "" ) ).toString())
path = str(settings.value( "/SextanteQGIS/LastInputPath",QtCore.QVariant("")).toString())
else:
path = ""

ret = QtGui.QFileDialog.getOpenFileNames(self, "Open file", path, "All files (*.*)")
ret = QtGui.QFileDialog.getOpenFileNames(self, "Open file", path, self.param.getFileFilter())
if ret:
files = list(ret)
if len(files) == 1:
Expand Down
40 changes: 24 additions & 16 deletions python/plugins/sextante/gui/BatchProcessingDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ def accept(self):
continue
widget = self.table.cellWidget(row, col)
if not self.setParameterValueFromWidget(param, widget, alg):
QMessageBox.critical(self, "Unable to execute batch process", "Wrong or missing parameter values")
self.progressLabel.setText("<b>Missing parameter value: " + param.description + " (row " + str(row + 1) + ")</b>")
#QMessageBox.critical(self, "Unable to execute batch process", "Wrong or missing parameter values")
self.algs = None
return
col+=1
Expand All @@ -167,7 +168,8 @@ def accept(self):
out.value = text
col+=1
else:
QMessageBox.critical(self, "Unable to execute batch process", "Wrong or missing parameter values")
self.progressLabel.setText("<b>Wrong or missing parameter value: " + out.description + " (row " + str(row + 1) + ")</b>")
#QMessageBox.critical(self, "Unable to execute batch process", "Wrong or missing parameter values")
self.algs = None
return
self.algs.append(alg)
Expand Down Expand Up @@ -205,30 +207,36 @@ def loadHTMLResults(self, alg, i):
def cancel(self):
self.algs = None
if self.algEx:
self.algEx.terminate()
self.close()
self.algEx.terminate()
self.table.setEnabled(True)
#self.close()

@pyqtSlot()
def finish(self, i):
if self.load[i]:
SextantePostprocessing.handleAlgorithmResults(self.algs[i], self, False)
i += 1
#self.progress.setValue(i)
if len(self.algs) == i:
self.finishAll()
self.algEx = None
else:
self.nextAlg(i)
if not self.stop:
if self.load[i]:
SextantePostprocessing.handleAlgorithmResults(self.algs[i], self, False)
i += 1
#self.progress.setValue(i)
if len(self.algs) == i:
self.finishAll()
self.algEx = None
else:
self.nextAlg(i)

@pyqtSlot()
@pyqtSlot(str)
def error(self, msg):
QApplication.restoreOverrideCursor()
QMessageBox.critical(self, "Error", msg)
SextanteLog.addToLog(SextanteLog.LOG_ERROR, msg)
self.close()
if self.algEx:
self.algEx.terminate()
self.table.setEnabled(True)
#self.close()


def nextAlg(self, i):
self.stop = False
self.setBaseText("Processing algorithm " + str(i) + "/" + str(len(self.algs)) + "...")
self.algEx = AlgorithmExecutor(self.algs[i]);
self.algEx.percentageChanged.connect(self.setPercentage)
Expand Down Expand Up @@ -265,7 +273,7 @@ def finishAll(self):
QApplication.restoreOverrideCursor()
self.table.setEnabled(True)
QMessageBox.information(self, "Batch processing", "Batch processing successfully completed!")
self.close()
#self.close()

def setParameterValueFromWidget(self, param, widget, alg = None):
if isinstance(param, (ParameterRaster, ParameterVector, ParameterTable, ParameterMultipleInput)):
Expand Down
10 changes: 1 addition & 9 deletions python/plugins/sextante/gui/HistoryDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,11 @@ def changeText(self):
if isinstance(item, TreeLogEntryItem):
self.text.setText(item.entry.text.replace("|","\n"))



def createTest(self):
item = self.tree.currentItem()
if isinstance(item, TreeLogEntryItem):
if item.isAlg:
TestTools.createTest(item)






TestTools.createTest(item.entry.text)

def showPopupMenu(self,point):
item = self.tree.currentItem()
Expand Down
10 changes: 5 additions & 5 deletions python/plugins/sextante/gui/TestTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
from sextante.core.QGisLayers import QGisLayers
from sextante.outputs.OutputVector import OutputVector

def createTest(item):
def createTest(text):
s = ""
tokens = item.entry.text[len("sextante.runalg("):-1].split(",")
tokens = text[len("sextante.runalg("):-1].split(",")
cmdname = tokens[0][1:-1];
methodname = "test_" + cmdname.replace(":","")
s += "def " + methodname + "():\n"
Expand All @@ -44,7 +44,7 @@ def createTest(item):
for token in tokens:
if i < alg.getVisibleParametersCount() + 1:
if os.path.exists(token[1:-1]):
token = '"' + os.path.basename(token[1:-1])[:-4] + '"'
token = os.path.basename(token[1:-1])[:-4]
execcommand+=token + ","
else:
execcommand+="None,"
Expand All @@ -69,8 +69,8 @@ def createTest(item):
fields = layer.pendingFields()
s+="\tlayer=sextante.getobject(output)\n"
s+="\tfields=layer.pendingFields()\n"
s+="\texpectednames=[" + ",".join([str(f.name()) for f in fields]) + "]\n"
s+="\texpectedtypes=[" + ",".join([str(f.typeName()) for f in fields]) + "]\n"
s+="\texpectednames=[" + ",".join(["'" + str(f.name()) + "'" for f in fields]) + "]\n"
s+="\texpectedtypes=[" + ",".join(["'" + str(f.typeName()) +"'" for f in fields]) + "]\n"
s+="\tnames=[str(f.name()) for f in fields]\n"
s+="\ttypes=[str(f.typeName()) for f in fields]\n"
s+="\tself.assertEqual(expectednames, names)\n"
Expand Down
3 changes: 1 addition & 2 deletions python/plugins/sextante/outputs/OutputRaster.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
* *
***************************************************************************
"""
from sextante.core.QGisLayers import QGisLayers
from sextante.core.SextanteRasterWriter import SextanteRasterWriter

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

from sextante.core.QGisLayers import QGisLayers
from sextante.outputs.Output import Output
from sextante.core.SextanteUtils import SextanteUtils

Expand Down
9 changes: 8 additions & 1 deletion python/plugins/sextante/parameters/ParameterMultipleInput.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,14 @@ def getAsString(self,value):
return unicode(layer.source())
return s


def getFileFilter(self):
if self.datatype == ParameterMultipleInput.TYPE_RASTER:
exts = QGisLayers.getSupportedOutputRasterLayerExtensions()
else:
exts = QGisLayers.getSupportedOutputVectorLayerExtensions()
for i in range(len(exts)):
exts[i] = exts[i].upper() + " files(*." + exts[i].lower() + ")"
return ";;".join(exts)

def serialize(self):
return self.__module__.split(".")[-1] + "|" + self.name + "|" + self.description +\
Expand Down
6 changes: 6 additions & 0 deletions python/plugins/sextante/parameters/ParameterRaster.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ def setValue(self, obj):
self.value = unicode(layer.dataProvider().dataSourceUri())
return True
return os.path.exists(self.value)

def getFileFilter(self):
exts = QGisLayers.getSupportedOutputRasterLayerExtensions()
for i in range(len(exts)):
exts[i] = exts[i].upper() + " files(*." + exts[i].lower() + ")"
return ";;".join(exts)

def serialize(self):
return self.__module__.split(".")[-1] + "|" + self.name + "|" + self.description +\
Expand Down
6 changes: 6 additions & 0 deletions python/plugins/sextante/parameters/ParameterTable.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ def getSafeExportedTable(self):
else:
self.exported = self.value
return self.exported

def getFileFilter(self,alg):
exts = ['csv', 'dbf']
for i in range(len(exts)):
exts[i] = exts[i].upper() + " files(*." + exts[i].lower() + ")"
return ";;".join(exts)

def serialize(self):
return self.__module__.split(".")[-1] + "|" + self.name + "|" + self.description +\
Expand Down
6 changes: 6 additions & 0 deletions python/plugins/sextante/parameters/ParameterVector.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ def getSafeExportedLayer(self):
else:
self.exported = self.value
return self.exported

def getFileFilter(self):
exts = QGisLayers.getSupportedOutputVectorLayerExtensions()
for i in range(len(exts)):
exts[i] = exts[i].upper() + " files(*." + exts[i].lower() + ")"
return ";;".join(exts)

def serialize(self):
return self.__module__.split(".")[-1] + "|" + self.name + "|" + self.description +\
Expand Down
23 changes: 4 additions & 19 deletions python/plugins/sextante/saga/SagaAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,29 +276,14 @@ def processAlgorithm(self, progress):

for out in self.outputs:
if isinstance(out, OutputRaster):
filename = out.getCompatibleFileName(self)#filename = out.value
#===============================================================
# if not filename.endswith(".tif"):
# filename += ".tif"
# out.value = filename
#===============================================================
filename = out.getCompatibleFileName(self)
filename = SextanteUtils.tempFolder() + os.sep + os.path.basename(filename) + ".sgrd"
command+=(" -" + out.name + " \"" + filename + "\"");
if isinstance(out, OutputVector):
filename = out.getCompatibleFileName(self)#out.value
#===============================================================
# if not filename.endswith(".shp"):
# filename += ".shp"
# out.value = filename
#===============================================================
filename = out.getCompatibleFileName(self)
command+=(" -" + out.name + " \"" + filename + "\"");
if isinstance(out, OutputTable):
filename = out.getCompatibleFileName(self)#out.value
#===============================================================
# if not filename.endswith(".dbf"):
# filename += ".dbf"
# out.value = filename
#===============================================================
filename = out.getCompatibleFileName(self)
command+=(" -" + out.name + " \"" + filename + "\"");

commands.append(command)
Expand Down Expand Up @@ -355,7 +340,7 @@ def resampleRasterLayer(self,layer):


def exportRasterLayer(self, layer):
destFilename = SextanteUtils.getTempFilename("sgrd")
destFilename = SextanteUtils.getTempFilenameInTempFolder(os.path.basename(layer)[0:5] + ".sgrd")
self.exportedLayers[layer]= destFilename
if SextanteUtils.isWindows():
return "io_gdal 0 -GRIDS \"" + destFilename + "\" -FILES \"" + layer+"\""
Expand Down