From 76d9ab82832332b9e1f1718d7cd14cd79e77bd63 Mon Sep 17 00:00:00 2001 From: volaya Date: Fri, 25 Jan 2019 09:39:45 +0100 Subject: [PATCH] [processing] fixed SAGA for non-ascii output files Fixes #19351 --- .../processing/algs/saga/SagaAlgorithm.py | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/python/plugins/processing/algs/saga/SagaAlgorithm.py b/python/plugins/processing/algs/saga/SagaAlgorithm.py index ce804974e6bd..6fff3748d03b 100644 --- a/python/plugins/processing/algs/saga/SagaAlgorithm.py +++ b/python/plugins/processing/algs/saga/SagaAlgorithm.py @@ -27,6 +27,7 @@ __revision__ = '$Format:%H$' import os +import shutil import importlib from qgis.core import (Qgis, QgsApplication, @@ -305,10 +306,19 @@ def processAlgorithm(self, parameters, context, feedback): output_layers = [] output_files = {} + #If the user has entered an output file that has non-ascii chars, we use a different path with only ascii chars + output_files_nonascii = {} for out in self.destinationParameterDefinitions(): filePath = self.parameterAsOutputLayer(parameters, out.name(), context) if isinstance(out, (QgsProcessingParameterRasterDestination, QgsProcessingParameterVectorDestination)): output_layers.append(filePath) + try: + filePath.encode('ascii') + except UnicodeEncodeError: + nonAsciiFilePath = filePath + filePath = QgsProcessingUtils.generateTempFilename(out.name() + os.path.splitext(filePath)[1]) + output_files_nonascii[filePath] = nonAsciiFilePath + output_files[out.name()] = filePath command += ' -{} "{}"'.format(out.name(), filePath) @@ -339,7 +349,18 @@ def processAlgorithm(self, parameters, context, feedback): for out in output_layers: prjFile = os.path.splitext(out)[0] + '.prj' with open(prjFile, 'w') as f: - f.write(crs.toWkt()) + f.write(crs.toWkt()) + + for old, new in output_files_nonascii.items(): + oldFolder = os.path.dirname(old) + newFolder = os.path.dirname(new) + newName = os.path.splitext(os.path.basename(new))[0] + files = [f for f in os.listdir(oldFolder)] + for f in files: + ext = os.path.splitext(f)[1] + newPath = os.path.join(newFolder, newName + ext) + oldPath = os.path.join(oldFolder, f) + shutil.move(oldPath, newPath) result = {} for o in self.outputDefinitions():