Skip to content
Permalink
Browse files

[processing] improved handling of output files and file naming

  • Loading branch information
volaya committed Sep 1, 2013
1 parent 979d876 commit 6607cedf1eadd98a7548d7c173f44f732d9ef9a6
@@ -29,7 +29,6 @@
from qgis.core import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from processing.gdal.GdalUtils import GdalUtils

class LayerExporter():

@@ -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):
@@ -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;

@@ -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):
@@ -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;


@@ -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
@@ -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):

0 comments on commit 6607ced

Please sign in to comment.
You can’t perform that action at this time.