Skip to content

Commit 76d9ab8

Browse files
committedJan 25, 2019
[processing] fixed SAGA for non-ascii output files
Fixes #19351
1 parent fda41e3 commit 76d9ab8

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed
 

‎python/plugins/processing/algs/saga/SagaAlgorithm.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
__revision__ = '$Format:%H$'
2828

2929
import os
30+
import shutil
3031
import importlib
3132
from qgis.core import (Qgis,
3233
QgsApplication,
@@ -305,10 +306,19 @@ def processAlgorithm(self, parameters, context, feedback):
305306

306307
output_layers = []
307308
output_files = {}
309+
#If the user has entered an output file that has non-ascii chars, we use a different path with only ascii chars
310+
output_files_nonascii = {}
308311
for out in self.destinationParameterDefinitions():
309312
filePath = self.parameterAsOutputLayer(parameters, out.name(), context)
310313
if isinstance(out, (QgsProcessingParameterRasterDestination, QgsProcessingParameterVectorDestination)):
311314
output_layers.append(filePath)
315+
try:
316+
filePath.encode('ascii')
317+
except UnicodeEncodeError:
318+
nonAsciiFilePath = filePath
319+
filePath = QgsProcessingUtils.generateTempFilename(out.name() + os.path.splitext(filePath)[1])
320+
output_files_nonascii[filePath] = nonAsciiFilePath
321+
312322
output_files[out.name()] = filePath
313323
command += ' -{} "{}"'.format(out.name(), filePath)
314324

@@ -339,7 +349,18 @@ def processAlgorithm(self, parameters, context, feedback):
339349
for out in output_layers:
340350
prjFile = os.path.splitext(out)[0] + '.prj'
341351
with open(prjFile, 'w') as f:
342-
f.write(crs.toWkt())
352+
f.write(crs.toWkt())
353+
354+
for old, new in output_files_nonascii.items():
355+
oldFolder = os.path.dirname(old)
356+
newFolder = os.path.dirname(new)
357+
newName = os.path.splitext(os.path.basename(new))[0]
358+
files = [f for f in os.listdir(oldFolder)]
359+
for f in files:
360+
ext = os.path.splitext(f)[1]
361+
newPath = os.path.join(newFolder, newName + ext)
362+
oldPath = os.path.join(oldFolder, f)
363+
shutil.move(oldPath, newPath)
343364

344365
result = {}
345366
for o in self.outputDefinitions():

0 commit comments

Comments
 (0)
Please sign in to comment.