Skip to content

Commit

Permalink
Merge pull request #4840 from nyalldawson/processing_next
Browse files Browse the repository at this point in the history
[processing] Simplify output creation
  • Loading branch information
nyalldawson committed Jul 12, 2017
2 parents 18b52b2 + 91d6ac9 commit 0b737ff
Show file tree
Hide file tree
Showing 46 changed files with 112 additions and 221 deletions.
12 changes: 11 additions & 1 deletion python/core/processing/qgsprocessingalgorithm.sip
Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 1 addition & 6 deletions python/plugins/processing/algs/qgis/AddTableField.py
Expand Up @@ -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


Expand Down Expand Up @@ -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'
Expand Down
8 changes: 1 addition & 7 deletions python/plugins/processing/algs/qgis/Aspect.py
Expand Up @@ -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

Expand Down Expand Up @@ -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'
Expand Down
7 changes: 1 addition & 6 deletions python/plugins/processing/algs/qgis/AutoincrementalField.py
Expand Up @@ -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


Expand All @@ -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')
Expand Down
2 changes: 0 additions & 2 deletions python/plugins/processing/algs/qgis/BasicStatistics.py
Expand Up @@ -32,11 +32,9 @@
from qgis.PyQt.QtGui import QIcon

from qgis.core import (QgsStatisticalSummary,
QgsFeatureSink,
QgsStringStatisticalSummary,
QgsDateTimeStatisticalSummary,
QgsFeatureRequest,
QgsProcessingUtils,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterField,
QgsProcessingParameterFileDestination,
Expand Down
9 changes: 1 addition & 8 deletions python/plugins/processing/algs/qgis/Boundary.py
Expand Up @@ -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]

Expand All @@ -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'))
Expand Down
9 changes: 1 addition & 8 deletions python/plugins/processing/algs/qgis/BoundingBox.py
Expand Up @@ -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]

Expand All @@ -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'
Expand Down
6 changes: 0 additions & 6 deletions python/plugins/processing/algs/qgis/CheckValidity.py
Expand Up @@ -37,15 +37,12 @@
QgsFeatureRequest,
QgsFeatureSink,
QgsWkbTypes,
QgsProcessingUtils,
QgsFields,
QgsProcessing,
QgsProcessingFeatureSource,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterEnum,
QgsProcessingParameterFeatureSink,
QgsProcessingOutputVectorLayer,
QgsProcessingParameterDefinition,
QgsProcessingOutputNumber
)
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
Expand Down Expand Up @@ -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):
Expand Down
12 changes: 2 additions & 10 deletions python/plugins/processing/algs/qgis/ConcaveHull.py
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down
2 changes: 0 additions & 2 deletions python/plugins/processing/algs/qgis/CreateAttributeIndex.py
Expand Up @@ -27,10 +27,8 @@

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

from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
Expand Down
6 changes: 1 addition & 5 deletions python/plugins/processing/algs/qgis/Delaunay.py
Expand Up @@ -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
Expand All @@ -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'
Expand Down
8 changes: 2 additions & 6 deletions python/plugins/processing/algs/qgis/DeleteColumn.py
Expand Up @@ -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


Expand All @@ -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'
Expand Down
9 changes: 2 additions & 7 deletions python/plugins/processing/algs/qgis/DeleteHoles.py
Expand Up @@ -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


Expand All @@ -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(',')
Expand Down
9 changes: 2 additions & 7 deletions python/plugins/processing/algs/qgis/DensifyGeometries.py
Expand Up @@ -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


Expand All @@ -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'
Expand Down
11 changes: 2 additions & 9 deletions python/plugins/processing/algs/qgis/DensifyGeometriesInterval.py
Expand Up @@ -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


Expand All @@ -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'
Expand Down
5 changes: 0 additions & 5 deletions python/plugins/processing/algs/qgis/Difference.py
Expand Up @@ -33,13 +33,9 @@
QgsFeatureSink,
QgsGeometry,
QgsFeatureRequest,
NULL,
QgsWkbTypes,
QgsMessageLog,
QgsProcessingUtils,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterFeatureSink,
QgsProcessingOutputVectorLayer,
QgsSpatialIndex)
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm

Expand Down Expand Up @@ -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'
Expand Down

0 comments on commit 0b737ff

Please sign in to comment.