|
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,14 +306,22 @@ 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 |
| - |
315 |
| - commands.append(command) |
| 324 | + commands.append(command) |
316 | 325 |
|
317 | 326 | # special treatment for RGB algorithm
|
318 | 327 | # TODO: improve this and put this code somewhere else
|
@@ -341,6 +350,17 @@ def processAlgorithm(self, parameters, context, feedback):
|
341 | 350 | with open(prjFile, 'w') as f:
|
342 | 351 | f.write(crs.toWkt())
|
343 | 352 |
|
| 353 | + for old, new in output_files_nonascii.items(): |
| 354 | + oldFolder = os.path.dirname(old) |
| 355 | + newFolder = os.path.dirname(new) |
| 356 | + newName = os.path.splitext(os.path.basename(new))[0] |
| 357 | + files = [f for f in os.listdir(oldFolder)] |
| 358 | + for f in files: |
| 359 | + ext = os.path.splitext(f)[1] |
| 360 | + newPath = os.path.join(newFolder, newName + ext) |
| 361 | + oldPath = os.path.join(oldFolder, f) |
| 362 | + shutil.move(oldPath, newPath) |
| 363 | + |
344 | 364 | result = {}
|
345 | 365 | for o in self.outputDefinitions():
|
346 | 366 | if o.name() in output_files:
|
@@ -421,8 +441,8 @@ def checkParameterValues(self, parameters, context):
|
421 | 441 |
|
422 | 442 | if isinstance(param, QgsProcessingParameterRasterLayer):
|
423 | 443 | raster_layer_params.append(param.name())
|
424 |
| - elif (isinstance(param, QgsProcessingParameterMultipleLayers) and |
425 |
| - param.layerType() == QgsProcessing.TypeRaster): |
| 444 | + elif (isinstance(param, QgsProcessingParameterMultipleLayers) |
| 445 | + and param.layerType() == QgsProcessing.TypeRaster): |
426 | 446 | raster_layer_params.extend(param.name())
|
427 | 447 |
|
428 | 448 | for layer_param in raster_layer_params:
|
|
0 commit comments