Skip to content
Permalink
Browse files

Merge pull request #4840 from nyalldawson/processing_next

[processing] Simplify output creation
  • Loading branch information
nyalldawson committed Jul 12, 2017
2 parents 18b52b2 + 91d6ac9 commit 0b737ff1f45dd3edb0ea65a45c79b60e25c1fd14
Showing with 112 additions and 221 deletions.
  1. +11 −1 python/core/processing/qgsprocessingalgorithm.sip
  2. +1 −6 python/plugins/processing/algs/qgis/AddTableField.py
  3. +1 −7 python/plugins/processing/algs/qgis/Aspect.py
  4. +1 −6 python/plugins/processing/algs/qgis/AutoincrementalField.py
  5. +0 −2 python/plugins/processing/algs/qgis/BasicStatistics.py
  6. +1 −8 python/plugins/processing/algs/qgis/Boundary.py
  7. +1 −8 python/plugins/processing/algs/qgis/BoundingBox.py
  8. +0 −6 python/plugins/processing/algs/qgis/CheckValidity.py
  9. +2 −10 python/plugins/processing/algs/qgis/ConcaveHull.py
  10. +0 −2 python/plugins/processing/algs/qgis/CreateAttributeIndex.py
  11. +1 −5 python/plugins/processing/algs/qgis/Delaunay.py
  12. +2 −6 python/plugins/processing/algs/qgis/DeleteColumn.py
  13. +2 −7 python/plugins/processing/algs/qgis/DeleteHoles.py
  14. +2 −7 python/plugins/processing/algs/qgis/DensifyGeometries.py
  15. +2 −9 python/plugins/processing/algs/qgis/DensifyGeometriesInterval.py
  16. +0 −5 python/plugins/processing/algs/qgis/Difference.py
  17. +1 −5 python/plugins/processing/algs/qgis/DropGeometry.py
  18. +1 −9 python/plugins/processing/algs/qgis/ExtentFromLayer.py
  19. +1 −4 python/plugins/processing/algs/qgis/FixGeometry.py
  20. +2 −8 python/plugins/processing/algs/qgis/GridPolygon.py
  21. +0 −2 python/plugins/processing/algs/qgis/ImportIntoPostGIS.py
  22. +0 −7 python/plugins/processing/algs/qgis/Merge.py
  23. +0 −3 python/plugins/processing/algs/qgis/PointsLayerFromTable.py
  24. +1 −2 python/plugins/processing/algs/qgis/PostGISExecuteSQL.py
  25. +1 −3 python/plugins/processing/algs/qgis/RandomExtract.py
  26. +2 −6 python/plugins/processing/algs/qgis/RandomExtractWithinSubsets.py
  27. +8 −6 python/plugins/processing/algs/qgis/RegularPoints.py
  28. +1 −3 python/plugins/processing/algs/qgis/SaveSelectedFeatures.py
  29. +0 −2 python/plugins/processing/algs/qgis/SelectByAttribute.py
  30. +3 −6 python/plugins/processing/algs/qgis/SimplifyGeometries.py
  31. +4 −8 python/plugins/processing/algs/qgis/Smooth.py
  32. +1 −4 python/plugins/processing/algs/qgis/SnapGeometries.py
  33. +0 −1 python/plugins/processing/algs/qgis/SpatialiteExecuteSQL.py
  34. +0 −3 python/plugins/processing/algs/qgis/SymmetricalDifference.py
  35. +0 −4 python/plugins/processing/algs/qgis/VoronoiPolygons.py
  36. +1 −4 python/plugins/processing/algs/qgis/ZonalStatistics.py
  37. +0 −2 python/plugins/processing/algs/qgis/scripts/Frequency_analysis.py
  38. +0 −3 python/plugins/processing/algs/qgis/scripts/Keep_n_biggest_parts.py
  39. +0 −2 python/plugins/processing/algs/qgis/scripts/Number_of_unique_values_in_classes.py
  40. +0 −4 python/plugins/processing/tests/testdata/scripts/centroids.py
  41. +0 −4 python/plugins/processing/tests/testdata/scripts/selectbyattribute.py
  42. +0 −4 python/plugins/processing/tests/testdata/scripts/selectbyexpression.py
  43. +0 −11 src/core/processing/qgsnativealgorithms.cpp
  44. +28 −2 src/core/processing/qgsprocessingalgorithm.cpp
  45. +13 −2 src/core/processing/qgsprocessingalgorithm.h
  46. +17 −2 tests/src/core/testqgsprocessing.cpp
@@ -392,14 +392,21 @@ class QgsProcessingAlgorithm
.. seealso:: addOutput()
%End

bool addParameter( QgsProcessingParameterDefinition *parameterDefinition /Transfer/ );
bool addParameter( QgsProcessingParameterDefinition *parameterDefinition /Transfer/, bool createOutput = true );
%Docstring
Adds a parameter ``definition`` to the algorithm. Ownership of the definition is transferred to the algorithm.
Returns true if parameter could be successfully added, or false if the parameter could not be added (e.g.
as a result of a duplicate name).

This should usually be called from a subclass' initAlgorithm() implementation.

If the ``createOutput`` argument is true, then a corresponding output definition will also be created
(and added to the algorithm) where appropriate. E.g. when adding a QgsProcessingParameterVectorDestination
and ``createOutput`` is true, then a QgsProcessingOutputVectorLayer output will be created and
added to the algorithm. There is no need to call addOutput() to manually add a corresponding output
for this vector. If ``createOutput`` is false then this automatic output creation will not
occur.

.. seealso:: initAlgorithm()
.. seealso:: addOutput()
:rtype: bool
@@ -419,6 +426,9 @@ class QgsProcessingAlgorithm

This should usually be called from a subclass' initAlgorithm() implementation.

Note that in some cases output creation can be automatically performed when calling addParameter().
See the notes in addParameter() for a description of when this occurs.

.. seealso:: addParameter()
.. seealso:: initAlgorithm()
:rtype: bool
@@ -27,16 +27,12 @@

from qgis.PyQt.QtCore import QVariant
from qgis.core import (QgsField,
QgsFeature,
QgsFeatureSink,
QgsApplication,
QgsProcessingUtils,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterString,
QgsProcessingParameterNumber,
QgsProcessingParameterEnum,
QgsProcessingParameterFeatureSink,
QgsProcessingOutputVectorLayer)
QgsProcessingParameterFeatureSink)
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm


@@ -73,7 +69,6 @@ def initAlgorithm(self, config=None):
self.addParameter(QgsProcessingParameterNumber(self.FIELD_PRECISION,
self.tr('Field precision'), QgsProcessingParameterNumber.Integer, 0, False, 0, 10))
self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT_LAYER, self.tr('Added')))
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT_LAYER, self.tr('Added')))

def name(self):
return 'addfieldtoattributestable'
@@ -32,13 +32,8 @@
from qgis.analysis import QgsAspectFilter
from qgis.core import (QgsProcessingParameterRasterLayer,
QgsProcessingParameterNumber,
QgsProcessingParameterRasterDestination,
QgsProcessingOutputRasterLayer,
QgsFeatureSink)
QgsProcessingParameterRasterDestination)
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
from processing.core.parameters import ParameterRaster
from processing.core.parameters import ParameterNumber
from processing.core.outputs import OutputRaster
from processing.tools import raster
from processing.tools.dataobjects import exportRasterLayer

@@ -67,7 +62,6 @@ def initAlgorithm(self, config=None):
self.tr('Z factor'), QgsProcessingParameterNumber.Double,
1, False, 1, 999999.99))
self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT, self.tr('Aspect')))
self.addOutput(QgsProcessingOutputRasterLayer(self.OUTPUT, self.tr('Aspect')))

def name(self):
return 'aspect'
@@ -27,13 +27,9 @@

from qgis.PyQt.QtCore import QVariant
from qgis.core import (QgsField,
QgsFeature,
QgsFeatureSink,
QgsApplication,
QgsProcessingUtils,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterFeatureSink,
QgsProcessingOutputVectorLayer)
QgsProcessingParameterFeatureSink)
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm


@@ -50,7 +46,6 @@ def initAlgorithm(self, config=None):
self.tr('Input layer')))

self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Incremented')))
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr('Incremented')))

def group(self):
return self.tr('Vector table tools')
@@ -32,11 +32,9 @@
from qgis.PyQt.QtGui import QIcon

from qgis.core import (QgsStatisticalSummary,
QgsFeatureSink,
QgsStringStatisticalSummary,
QgsDateTimeStatisticalSummary,
QgsFeatureRequest,
QgsProcessingUtils,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterField,
QgsProcessingParameterFileDestination,
@@ -31,19 +31,13 @@
QgsWkbTypes,
QgsFeatureSink,
QgsProcessing,
QgsProcessingUtils,
QgsProcessingParameterDefinition,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterFeatureSink,
QgsProcessingOutputVectorLayer)
QgsProcessingParameterFeatureSink)

from qgis.PyQt.QtGui import QIcon

from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from processing.core.parameters import ParameterVector
from processing.core.outputs import OutputVector
from processing.tools import dataobjects

pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]

@@ -59,7 +53,6 @@ def __init__(self):
def initAlgorithm(self, config=None):
self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT_LAYER, self.tr('Input layer'), [QgsProcessing.TypeVectorLine, QgsProcessing.TypeVectorPolygon]))
self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT_LAYER, self.tr('Boundary')))
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT_LAYER, self.tr("Boundaries")))

def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'ftools', 'convex_hull.png'))
@@ -31,20 +31,14 @@
QgsWkbTypes,
QgsFeatureSink,
QgsProcessing,
QgsProcessingUtils,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterFeatureSink,
QgsProcessingOutputVectorLayer,
QgsProcessingParameterDefinition)
QgsProcessingParameterFeatureSink)


from qgis.PyQt.QtGui import QIcon

from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from processing.core.parameters import ParameterVector
from processing.core.outputs import OutputVector
from processing.tools import dataobjects

pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]

@@ -66,7 +60,6 @@ def __init__(self):
def initAlgorithm(self, config=None):
self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT_LAYER, self.tr('Input layer')))
self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT_LAYER, self.tr('Bounds'), QgsProcessing.TypeVectorPolygon))
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT_LAYER, self.tr("Bounds")))

def name(self):
return 'boundingboxes'
@@ -37,15 +37,12 @@
QgsFeatureRequest,
QgsFeatureSink,
QgsWkbTypes,
QgsProcessingUtils,
QgsFields,
QgsProcessing,
QgsProcessingFeatureSource,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterEnum,
QgsProcessingParameterFeatureSink,
QgsProcessingOutputVectorLayer,
QgsProcessingParameterDefinition,
QgsProcessingOutputNumber
)
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
@@ -85,15 +82,12 @@ def initAlgorithm(self, config=None):
self.tr('Method'), self.methods))

self.addParameter(QgsProcessingParameterFeatureSink(self.VALID_OUTPUT, self.tr('Valid output'), QgsProcessing.TypeVectorAny, '', True))
self.addOutput(QgsProcessingOutputVectorLayer(self.VALID_OUTPUT, self.tr('Valid output')))
self.addOutput(QgsProcessingOutputNumber(self.VALID_COUNT, self.tr('Count of valid features')))

self.addParameter(QgsProcessingParameterFeatureSink(self.INVALID_OUTPUT, self.tr('Invalid output'), QgsProcessing.TypeVectorAny, '', True))
self.addOutput(QgsProcessingOutputVectorLayer(self.INVALID_OUTPUT, self.tr('Invalid output')))
self.addOutput(QgsProcessingOutputNumber(self.INVALID_COUNT, self.tr('Count of invalid features')))

self.addParameter(QgsProcessingParameterFeatureSink(self.ERROR_OUTPUT, self.tr('Error output'), QgsProcessing.TypeVectorAny, '', True))
self.addOutput(QgsProcessingOutputVectorLayer(self.ERROR_OUTPUT, self.tr('Error output')))
self.addOutput(QgsProcessingOutputNumber(self.ERROR_COUNT, self.tr('Count of errors')))

def name(self):
@@ -26,21 +26,14 @@

__revision__ = '$Format:%H$'

from qgis.core import (QgsFeatureRequest,
QgsFeature,
QgsGeometry,
from qgis.core import (QgsFeature,
QgsFeatureSink,
QgsWkbTypes,
QgsApplication,
QgsProcessing,
QgsProcessingUtils,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterVectorLayer,
QgsProcessingParameterDefinition,
QgsProcessingParameterNumber,
QgsProcessingParameterBoolean,
QgsProcessingParameterFeatureSink,
QgsProcessingOutputVectorLayer)
QgsProcessingParameterFeatureSink)
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
import processing
@@ -73,7 +66,6 @@ def initAlgorithm(self, config=None):
self.tr('Split multipart geometry into singleparts geometries'), defaultValue=False))

self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Concave hull'), type=QgsProcessing.TypeVectorPolygon))
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr("Concave hull"), type=QgsProcessing.TypeVectorPolygon))

def name(self):
return 'concavehull'
@@ -27,10 +27,8 @@

from qgis.core import (QgsVectorDataProvider,
QgsFields,
QgsApplication,
QgsProcessingParameterVectorLayer,
QgsProcessingParameterField,
QgsProcessingParameterDefinition,
QgsProcessingOutputVectorLayer)

from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
@@ -39,12 +39,9 @@
QgsPointXY,
QgsWkbTypes,
QgsProcessing,
QgsProcessingUtils,
QgsFields,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterDefinition,
QgsProcessingParameterFeatureSink,
QgsProcessingOutputVectorLayer)
QgsProcessingParameterFeatureSink)

from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
@@ -71,7 +68,6 @@ def __init__(self):
def initAlgorithm(self, config=None):
self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Input layer'), [QgsProcessing.TypeVectorPoint]))
self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Delaunay triangulation'), type=QgsProcessing.TypeVectorPolygon))
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr("Delaunay triangulation"), type=QgsProcessing.TypeVectorPolygon))

def name(self):
return 'delaunaytriangulation'
@@ -25,13 +25,10 @@

__revision__ = '$Format:%H$'

from qgis.core import (QgsApplication,
QgsFeatureSink,
QgsProcessingUtils,
from qgis.core import (QgsFeatureSink,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterFeatureSink,
QgsProcessingParameterField,
QgsProcessingOutputVectorLayer)
QgsProcessingParameterField)
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm


@@ -57,7 +54,6 @@ def initAlgorithm(self, config=None):
None, self.INPUT, QgsProcessingParameterField.Any, True))

self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Output layer')))
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr("Output layer")))

def name(self):
return 'deletecolumn'
@@ -24,15 +24,11 @@

__revision__ = '$Format:%H$'

from qgis.core import (QgsApplication,
QgsFeatureSink,
from qgis.core import (QgsFeatureSink,
QgsProcessing,
QgsProcessingUtils,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterNumber,
QgsProcessingParameterFeatureSink,
QgsProcessingOutputVectorLayer,
QgsProcessingParameterDefinition)
QgsProcessingParameterFeatureSink)
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm


@@ -53,7 +49,6 @@ def initAlgorithm(self, config=None):
0, True, 0.0, 10000000.0))

self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Cleaned'), QgsProcessing.TypeVectorPolygon))
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr('Cleaned'), QgsProcessing.TypeVectorPolygon))

def tags(self):
return self.tr('remove,delete,drop,holes,rings,fill').split(',')
@@ -28,15 +28,11 @@

import os

from qgis.core import (QgsWkbTypes,
QgsFeatureSink,
QgsApplication,
from qgis.core import (QgsFeatureSink,
QgsProcessing,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterNumber,
QgsProcessingParameterFeatureSink,
QgsProcessingOutputVectorLayer,
QgsProcessingParameterDefinition)
QgsProcessingParameterFeatureSink)
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm


@@ -63,7 +59,6 @@ def initAlgorithm(self, config=None):
1, False, 1, 10000000))

self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Densified')))
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr('Densified')))

def name(self):
return 'densifygeometries'
@@ -27,17 +27,11 @@

__revision__ = '$Format:%H$'

from math import sqrt

from qgis.core import (QgsWkbTypes,
QgsApplication,
QgsFeatureSink,
from qgis.core import (QgsFeatureSink,
QgsProcessing,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterNumber,
QgsProcessingParameterFeatureSink,
QgsProcessingOutputVectorLayer,
QgsProcessingParameterDefinition)
QgsProcessingParameterFeatureSink)
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm


@@ -61,7 +55,6 @@ def initAlgorithm(self, config=None):
1, False, 0, 10000000))

self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Densified')))
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr('Densified')))

def name(self):
return 'densifygeometriesgivenaninterval'
@@ -33,13 +33,9 @@
QgsFeatureSink,
QgsGeometry,
QgsFeatureRequest,
NULL,
QgsWkbTypes,
QgsMessageLog,
QgsProcessingUtils,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterFeatureSink,
QgsProcessingOutputVectorLayer,
QgsSpatialIndex)
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm

@@ -68,7 +64,6 @@ def initAlgorithm(self, config=None):
self.tr('Difference layer')))

self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Difference')))
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr('Difference')))

def name(self):
return 'difference'

0 comments on commit 0b737ff

Please sign in to comment.
You can’t perform that action at this time.