Fix multiple enum parameters handling and some ext scripts

This commit is contained in:
Médéric RIBREUX 2017-12-27 11:16:14 +01:00
parent 3fa9e3c9f8
commit 36311ff6af
7 changed files with 15 additions and 56 deletions

@ -524,8 +524,12 @@ class Grass7Algorithm(QgsProcessingAlgorithm):
command += ' {}'.format(paramName) command += ' {}'.format(paramName)
# For enumeration, we need to grab the string value # For enumeration, we need to grab the string value
elif isinstance(param, QgsProcessingParameterEnum): elif isinstance(param, QgsProcessingParameterEnum):
idx = self.parameterAsEnum(parameters, paramName, context) # Handle multiple values
value = '"{}"'.format(param.options()[idx]) if param.allowMultiple():
indexes = self.parameterAsEnums(parameters, paramName, context)
else:
indexes = [self.parameterAsEnum(parameters, paramName, context)]
value = '"{}"'.format(','.join([param.options()[i] for i in indexes]))
# For strings, we just translate as string # For strings, we just translate as string
elif isinstance(param, QgsProcessingParameterString): elif isinstance(param, QgsProcessingParameterString):
data = self.parameterAsString(parameters, paramName, context) data = self.parameterAsString(parameters, paramName, context)

@ -14,12 +14,6 @@ QGIS3 Processing Port
* r_mask_vect.py * r_mask_vect.py
* r_mask_rast.py * r_mask_rast.py
* r_statistics.py * r_statistics.py
* v_voronoi.py
* v_to_3d.py.
* v_what_rast_points.py.
* v_what_rast_centroids.py.
* v_vect_stats.py
* v_rast_stats.py
* v_net.py * v_net.py
* v_net_alloc.py * v_net_alloc.py
* v_net_allpairs.py * v_net_allpairs.py

@ -34,6 +34,6 @@ def processCommand(alg, parameters, context):
def processOutputs(alg, parameters, context): def processOutputs(alg, parameters, context):
# We need to add the initial vector layer to outputs: # We need to add the initial vector layer to outputs:
fileName = alg.parameterAsOutputLayer(parameters, 'output', context) fileName = alg.parameterAsOutputLayer(parameters, 'output', context)
grassName = '{}{}'.format('map', alg.uniqueSuffix) grassName = alg.exportedLayers['map']
dataType = 'auto' dataType = 'auto'
alg.exportVectorLayer(grassName, fileName, dataType) alg.exportVectorLayer(grassName, fileName, dataType)

@ -40,6 +40,6 @@ def processInputs(alg, parameters, context):
if 'input' in alg.exportedLayers: if 'input' in alg.exportedLayers:
return return
# We need to import all the bands and color tables of the input raster # We need to import the vector layer with v.in.ogr
alg.loadVectorLayerFromParameter('input', parameters, context, False) alg.loadVectorLayerFromParameter('input', parameters, context, False)
alg.postInputs() alg.postInputs()

@ -34,6 +34,6 @@ def processCommand(alg, parameters, context):
def processOutputs(alg, parameters, context): def processOutputs(alg, parameters, context):
# We need to add the initial vector layer to outputs: # We need to add the initial vector layer to outputs:
fileName = alg.parameterAsOutputLayer(parameters, 'output', context) fileName = alg.parameterAsOutputLayer(parameters, 'output', context)
grassName = '{}{}'.format('map', alg.uniqueSuffix) grassName = alg.exportedLayers['areas']
dataType = 'auto' dataType = 'auto'
alg.exportVectorLayer(grassName, fileName, dataType) alg.exportVectorLayer(grassName, fileName, dataType)

@ -2,10 +2,10 @@
""" """
*************************************************************************** ***************************************************************************
v_what_rast_points.py v_what_rast.py
--------------------- ---------------------
Date : January 2016 Date : December 2017
Copyright : (C) 2016 by Médéric Ribreux Copyright : (C) 2017 by Médéric Ribreux
Email : medspx at medspx dot fr Email : medspx at medspx dot fr
*************************************************************************** ***************************************************************************
* * * *
@ -18,8 +18,8 @@
""" """
__author__ = 'Médéric Ribreux' __author__ = 'Médéric Ribreux'
__date__ = 'January 2016' __date__ = 'December 2017'
__copyright__ = '(C) 2016, Médéric Ribreux' __copyright__ = '(C) 2017, Médéric Ribreux'
# This will get replaced with a git SHA1 when you do a git archive # This will get replaced with a git SHA1 when you do a git archive
@ -34,6 +34,6 @@ def processCommand(alg, parameters, context):
def processOutputs(alg, parameters, context): def processOutputs(alg, parameters, context):
# We need to add the initial vector layer to outputs: # We need to add the initial vector layer to outputs:
fileName = alg.parameterAsOutputLayer(parameters, 'output', context) fileName = alg.parameterAsOutputLayer(parameters, 'output', context)
grassName = '{}{}'.format('map', alg.uniqueSuffix) grassName = alg.exportedLayers['map']
dataType = 'auto' dataType = 'auto'
alg.exportVectorLayer(grassName, fileName, dataType) alg.exportVectorLayer(grassName, fileName, dataType)

@ -1,39 +0,0 @@
# -*- coding: utf-8 -*-
"""
***************************************************************************
v_what_rast_centroids.py
------------------------
Date : January 2016
Copyright : (C) 2016 by Médéric Ribreux
Email : medspx at medspx dot fr
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""
__author__ = 'Médéric Ribreux'
__date__ = 'January 2016'
__copyright__ = '(C) 2016, Médéric Ribreux'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'
def processCommand(alg, parameters, context):
# Exclude outputs from commands
alg.processCommand(parameters, context, True)
def processOutputs(alg, parameters, context):
# We need to add the initial vector layer to outputs:
fileName = alg.parameterAsOutputLayer(parameters, 'output', context)
grassName = '{}{}'.format('map', alg.uniqueSuffix)
dataType = 'auto'
alg.exportVectorLayer(grassName, fileName, dataType)