|
59 | 59 | QgsProcessingOutputHtml)
|
60 | 60 | from qgis.utils import iface
|
61 | 61 |
|
62 |
| -#from processing.core.GeoAlgorithm import GeoAlgorithm (replaced by QgsProcessingAlgorithm) |
63 | 62 | from processing.core.ProcessingConfig import ProcessingConfig
|
64 |
| -#from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException (replaced by QgsProcessingException). |
65 | 63 |
|
66 | 64 | from processing.core.parameters import (getParameterFromString)
|
67 |
| -#from processing.core.outputs import (getOutputFromString, |
68 |
| -# OutputRaster, |
69 |
| -# OutputVector, |
70 |
| -# OutputFile, |
71 |
| -# OutputHTML) |
72 | 65 |
|
73 | 66 | from .Grass7Utils import Grass7Utils
|
74 | 67 |
|
@@ -183,7 +176,6 @@ def initAlgorithm(self, config=None):
|
183 | 176 | def defineCharacteristicsFromFile(self):
|
184 | 177 | """
|
185 | 178 | Create algorithm parameters and outputs from a text file.
|
186 |
| - |
187 | 179 | """
|
188 | 180 | with open(self.descriptionFile) as lines:
|
189 | 181 | # First line of the file is the Grass algorithm name
|
@@ -308,6 +300,7 @@ def grabDefaultGrassParameters(self, parameters, context):
|
308 | 300 | self.region = self.parameterAsExtent(parameters,
|
309 | 301 | self.GRASS_REGION_EXTENT_PARAMETER,
|
310 | 302 | context)
|
| 303 | + QgsMessageLog.logMessage('processAlgorithm self.region: {}'.format(self.region.isEmpty()), 'Grass7', QgsMessageLog.INFO) |
311 | 304 | # GRASS cell size
|
312 | 305 | self.cellSize = self.parameterAsString(parameters,
|
313 | 306 | self.GRASS_REGION_CELLSIZE_PARAMETER,
|
@@ -426,24 +419,25 @@ def processInputs(self, parameters, context):
|
426 | 419 | if not paramName in parameters:
|
427 | 420 | continue
|
428 | 421 | layer = self.parameterAsRasterLayer(parameters, paramName, context)
|
429 |
| - layerSrc = self.parameterAsCompatibleSourceLayerPath(parameters, paramName, context, |
430 |
| - QgsVectorFileWriter.supportedFormatExtensions()) |
431 |
| - |
| 422 | + layerSrc = parameters[paramName] |
432 | 423 | # Check if the layer hasn't already been exported in, for
|
433 | 424 | # example, previous GRASS calls in this session
|
434 | 425 | if paramName in self.exportedLayers:
|
435 | 426 | continue
|
436 | 427 | else:
|
| 428 | + layers.append(layer) |
437 | 429 | self.setSessionProjectionFromLayer(layer)
|
438 | 430 | self.commands.append(self.exportRasterLayer(paramName, layerSrc))
|
439 | 431 | # Vector inputs needs to be imported into temp GRASS DB
|
440 | 432 | if isinstance(param, QgsProcessingParameterVectorLayer):
|
441 | 433 | if not paramName in parameters:
|
442 | 434 | continue
|
443 | 435 | layer = self.parameterAsVectorLayer(parameters, paramName, context)
|
444 |
| - layerSrc = self.parameterAsCompatibleSourceLayerPath(parameters, paramName, context, |
445 |
| - QgsVectorFileWriter.supportedFormatExtensions()) |
446 |
| - |
| 436 | + layerSrc = self.parameterAsCompatibleSourceLayerPath( |
| 437 | + parameters, paramName, context, |
| 438 | + self.provider().supportedOutputVectorLayerExtensions() |
| 439 | + ) |
| 440 | + |
447 | 441 | if paramName in self.exportedLayers:
|
448 | 442 | continue
|
449 | 443 | else:
|
@@ -482,11 +476,11 @@ def processInputs(self, parameters, context):
|
482 | 476 | self.setSessionProjectionFromProject()
|
483 | 477 |
|
484 | 478 | # Build GRASS region
|
485 |
| - if not self.region: |
| 479 | + if self.region.isEmpty(): |
486 | 480 | self.region = QgsProcessingUtils.combineLayerExtents(layers)
|
487 | 481 | command = 'g.region n={} s={} e={} w={}'.format(
|
488 | 482 | self.region.yMaximum(), self.region.yMinimum(),
|
489 |
| - self.region.xMinimum(), self.region.xMaximum() |
| 483 | + self.region.xMaximum(), self.region.xMinimum() |
490 | 484 | )
|
491 | 485 | # TODO Handle cell size
|
492 | 486 | #if not self.cellSize:
|
@@ -625,7 +619,7 @@ def processOutputs(self, parameters, context):
|
625 | 619 | self.commands.append(command)
|
626 | 620 | self.outputCommands.append(command)
|
627 | 621 | else:
|
628 |
| - command += ' {} output="{}"'.format(uniqName, fileName) |
| 622 | + command += '{} output="{}"'.format(uniqName, fileName) |
629 | 623 | self.commands.append(command)
|
630 | 624 | self.outputCommands.append(command)
|
631 | 625 |
|
@@ -712,6 +706,10 @@ def setSessionProjectionFromLayer(self, layer):
|
712 | 706 | Grass7Utils.projectionSet = True
|
713 | 707 |
|
714 | 708 | def exportRasterLayer(self, layerKey, layerSrc):
|
| 709 | + """ |
| 710 | + Creates a dedicated command to load a raster into |
| 711 | + temporary GRASS DB. |
| 712 | + """ |
715 | 713 | # TODO: handle multiple bands
|
716 | 714 | destFilename = 'a' + os.path.basename(self.getTempFilename())
|
717 | 715 | self.exportedLayers[layerKey] = destFilename
|
|
0 commit comments