Skip to content

Commit

Permalink
[processing] improved handling of output files and file naming
Browse files Browse the repository at this point in the history
  • Loading branch information
volaya committed Sep 2, 2013
1 parent 979d876 commit 6607ced
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 15 deletions.
1 change: 0 additions & 1 deletion python/plugins/processing/core/LayerExporter.py
Expand Up @@ -29,7 +29,6 @@
from qgis.core import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from processing.gdal.GdalUtils import GdalUtils

class LayerExporter():

Expand Down
6 changes: 1 addition & 5 deletions python/plugins/processing/core/ProcessingUtils.py
Expand Up @@ -61,11 +61,7 @@ def tempFolder():
@staticmethod
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("-","")
filename = ProcessingUtils.tempFolder() + os.sep + safeCmdName + uniqueSufix + "." + ext
out.value = filename
out.value = ProcessingUtils.getTempFilenameInTempFolder(out.name + "." + ext)

@staticmethod
def getTempFilename(ext):
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/outputs/OutputRaster.py
Expand Up @@ -49,6 +49,6 @@ def getCompatibleFileName(self, alg):
return self.value
else:
if self.compatible is None:
self.compatible = ProcessingUtils.getTempFilename(self.getDefaultFileExtension(alg))
self.compatible = ProcessingUtils.getTempFilenameInTempFolder(self.name + "." + self.getDefaultFileExtension(alg))
return self.compatible;

2 changes: 1 addition & 1 deletion python/plugins/processing/outputs/OutputTable.py
Expand Up @@ -52,7 +52,7 @@ def getCompatibleFileName(self, alg):
return self.value
else:
if self.compatible is None:
self.compatible = ProcessingUtils.getTempFilename(self.getDefaultFileExtension(alg))
self.compatible = ProcessingUtils.getTempFilenameInTempFolder(self.name + "." + self.getDefaultFileExtension(alg))
return self.compatible;

def getTableWriter(self, fields):
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/outputs/OutputVector.py
Expand Up @@ -55,7 +55,7 @@ def getCompatibleFileName(self, alg):
return self.value
else:
if self.compatible is None:
self.compatible = ProcessingUtils.getTempFilename(self.getDefaultFileExtension(alg))
self.compatible = ProcessingUtils.getTempFilenameInTempFolder(self.name + "." + self.getDefaultFileExtension(alg))
return self.compatible;


Expand Down
23 changes: 17 additions & 6 deletions python/plugins/processing/saga/SagaAlgorithm.py
Expand Up @@ -206,7 +206,7 @@ def processAlgorithm(self, progress):
filename = LayerExporter.exportVectorLayer(layer)
self.exportedLayers[param.value]=filename
elif not param.value.endswith("shp"):
raise GeoAlgorithmExecutionException("Unsupported file format")
raise GeoAlgorithmExecutionException("Unsupported file format")
if isinstance(param, ParameterTable):
if param.value == None:
continue
Expand Down Expand Up @@ -378,14 +378,25 @@ def resampleRasterLayer(self,layer):
return s


def exportRasterLayer(self, layer):
destFilename = ProcessingUtils.getTempFilenameInTempFolder(os.path.basename(layer)[0:5] + ".sgrd")
self.exportedLayers[layer]= destFilename
def exportRasterLayer(self, source):
layer = QGisLayers.getObjectFromUri(source, False)
if layer:
filename = str(layer.name())
else:
filename = source.rstrip(".sgrd")
validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:"
filename = ''.join(c for c in filename if c in validChars)
if len(filename) == 0:
filename = "layer"
destFilename = ProcessingUtils.getTempFilenameInTempFolder(filename + ".sgrd")
self.exportedLayers[source]= destFilename
saga208 = ProcessingConfig.getSetting(SagaUtils.SAGA_208)
if ProcessingUtils.isWindows() or ProcessingUtils.isMac() or not saga208:
return "io_gdal 0 -GRIDS \"" + destFilename + "\" -FILES \"" + layer+"\""
return "io_gdal 0 -GRIDS \"" + destFilename + "\" -FILES \"" + source+"\""
else:
return "libio_gdal 0 -GRIDS \"" + destFilename + "\" -FILES \"" + layer + "\""
return "libio_gdal 0 -GRIDS \"" + destFilename + "\" -FILES \"" + source + "\""




def checkBeforeOpeningParametersDialog(self):
Expand Down

0 comments on commit 6607ced

Please sign in to comment.