|
27 | 27 | __revision__ = '$Format:%H$'
|
28 | 28 |
|
29 | 29 | import os
|
| 30 | +import shutil |
30 | 31 | import importlib
|
31 | 32 | from qgis.core import (Qgis,
|
32 | 33 | QgsApplication,
|
@@ -305,10 +306,19 @@ def processAlgorithm(self, parameters, context, feedback):
|
305 | 306 |
|
306 | 307 | output_layers = []
|
307 | 308 | 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 = {} |
308 | 311 | for out in self.destinationParameterDefinitions():
|
309 | 312 | filePath = self.parameterAsOutputLayer(parameters, out.name(), context)
|
310 | 313 | if isinstance(out, (QgsProcessingParameterRasterDestination, QgsProcessingParameterVectorDestination)):
|
311 | 314 | 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 | + |
312 | 322 | output_files[out.name()] = filePath
|
313 | 323 | command += ' -{} "{}"'.format(out.name(), filePath)
|
314 | 324 |
|
@@ -339,7 +349,18 @@ def processAlgorithm(self, parameters, context, feedback):
|
339 | 349 | for out in output_layers:
|
340 | 350 | prjFile = os.path.splitext(out)[0] + '.prj'
|
341 | 351 | 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) |
343 | 364 |
|
344 | 365 | result = {}
|
345 | 366 | for o in self.outputDefinitions():
|
|
0 commit comments