Skip to content
Permalink
Browse files

[processing] fixed SAGA for non-ascii output files

Fixes #19351
  • Loading branch information
volaya committed Jan 25, 2019
1 parent fda41e3 commit 76d9ab82832332b9e1f1718d7cd14cd79e77bd63
Showing with 22 additions and 1 deletion.
  1. +22 −1 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():

0 comments on commit 76d9ab8

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