Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[processing] fixed SAGA for non-ascii output files
Fixes #19351
  • Loading branch information
volaya committed Jan 25, 2019
1 parent fda41e3 commit 76d9ab8
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion python/plugins/processing/algs/saga/SagaAlgorithm.py
Expand Up @@ -27,6 +27,7 @@
__revision__ = '$Format:%H$'

import os
import shutil
import importlib
from qgis.core import (Qgis,
QgsApplication,
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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():
Expand Down

0 comments on commit 76d9ab8

Please sign in to comment.