Skip to content
Permalink
Browse files

Port boundary algorithm to c++

Also allow feature based algorithms to customise their appectable
input layers types and set suitable filters for all applicable
algorithms
  • Loading branch information
nyalldawson committed Oct 12, 2017
1 parent 97c1b0d commit 2951afa3241a9188b46ff107a7cac397a1d2076a
@@ -801,6 +801,14 @@ class QgsProcessingFeatureBasedAlgorithm : QgsProcessingAlgorithm
:rtype: str
%End

virtual QList<int> inputLayerTypes() const;
%Docstring
Returns the valid input layer types for the source layer for this algorithm.
By default vector layers with any geometry types (excluding non-spatial, geometryless layers)
are accepted.
:rtype: list of int
%End

virtual QgsProcessing::SourceType outputLayerType() const;
%Docstring
Returns the layer type for layers generated by this algorithm, if
@@ -27,6 +27,7 @@

from qgis.PyQt.QtCore import QVariant
from qgis.core import (QgsField,
QgsProcessing,
QgsProcessingParameterString,
QgsProcessingParameterNumber,
QgsProcessingParameterEnum)
@@ -72,6 +73,9 @@ def displayName(self):
def outputName(self):
return self.tr('Added')

def inputLayerTypes(self):
return [QgsProcessing.TypeVector]

def prepareAlgorithm(self, parameters, context, feedback):
field_type = self.parameterAsEnum(parameters, self.FIELD_TYPE, context)
field_name = self.parameterAsString(parameters, self.FIELD_NAME, context)

This file was deleted.

@@ -25,7 +25,8 @@

__revision__ = '$Format:%H$'

from qgis.core import (QgsProcessingParameterField)
from qgis.core import (QgsProcessingParameterField,
QgsProcessing)
from processing.algs.qgis.QgisAlgorithm import QgisFeatureBasedAlgorithm


@@ -49,6 +50,9 @@ def initParameters(self, config=None):
self.tr('Fields to drop'),
None, 'INPUT', QgsProcessingParameterField.Any, True))

def inputLayerTypes(self):
return [QgsProcessing.TypeVector]

def name(self):
return 'deletecolumn'

@@ -24,7 +24,8 @@

__revision__ = '$Format:%H$'

from qgis.core import (QgsProcessingParameterNumber)
from qgis.core import (QgsProcessingParameterNumber,
QgsProcessing)
from processing.algs.qgis.QgisAlgorithm import QgisFeatureBasedAlgorithm


@@ -56,6 +57,9 @@ def displayName(self):
def outputName(self):
return self.tr('Cleaned')

def inputLayerTypes(self):
return [QgsProcessing.TypeVectorPolygon]

def prepareAlgorithm(self, parameters, context, feedback):
self.min_area = self.parameterAsDouble(parameters, self.MIN_AREA, context)
if self.min_area == 0.0:
@@ -28,7 +28,8 @@

import os

from qgis.core import (QgsProcessingParameterNumber)
from qgis.core import (QgsProcessingParameterNumber,
QgsProcessing)

from processing.algs.qgis.QgisAlgorithm import QgisFeatureBasedAlgorithm

@@ -61,6 +62,9 @@ def displayName(self):
def outputName(self):
return self.tr('Densified')

def inputLayerTypes(self):
return [QgsProcessing.TypeVectorLine, QgsProcessing.TypeVectorPolygon]

def prepareAlgorithm(self, parameters, context, feedback):
self.vertices = self.parameterAsInt(parameters, self.VERTICES, context)
return True
@@ -27,7 +27,8 @@

__revision__ = '$Format:%H$'

from qgis.core import (QgsProcessingParameterNumber)
from qgis.core import (QgsProcessingParameterNumber,
QgsProcessing)

from processing.algs.qgis.QgisAlgorithm import QgisFeatureBasedAlgorithm

@@ -57,6 +58,9 @@ def displayName(self):
def outputName(self):
return self.tr('Densified')

def inputLayerTypes(self):
return [QgsProcessing.TypeVectorLine, QgsProcessing.TypeVectorPolygon]

def prepareAlgorithm(self, parameters, context, feedback):
interval = self.parameterAsDouble(parameters, self.INTERVAL, context)
return True
@@ -26,7 +26,8 @@
__revision__ = '$Format:%H$'

from qgis.core import (QgsProcessingParameterNumber,
QgsProcessingException)
QgsProcessingException,
QgsProcessing)
from processing.algs.qgis.QgisAlgorithm import QgisFeatureBasedAlgorithm


@@ -58,6 +59,9 @@ def displayName(self):
def outputName(self):
return self.tr('Extended')

def inputLayerTypes(self):
return [QgsProcessing.TypeVectorLine]

def prepareAlgorithm(self, parameters, context, feedback):
self.start_distance = self.parameterAsDouble(parameters, self.START_DISTANCE, context)
self.end_distance = self.parameterAsDouble(parameters, self.END_DISTANCE, context)
@@ -30,6 +30,7 @@
QgsExpression,
QgsField,
QgsFields,
QgsProcessing,
QgsProcessingException,
QgsProcessingParameterDefinition)

@@ -103,6 +104,9 @@ def displayName(self):
def outputName(self):
return self.tr('Refactored')

def inputLayerTypes(self):
return [QgsProcessing.TypeVector]

def parameterAsFieldsMapping(self, parameters, name, context):
return parameters[name]

@@ -74,6 +74,9 @@ def outputName(self):
def outputType(self):
return QgsProcessing.TypeVectorPolygon

def inputLayerTypes(self):
return [QgsProcessing.TypeVectorLine]

def outputWkbType(self, input_wkb_type):
return self.convertWkbToPolygons(input_wkb_type)

@@ -87,6 +87,9 @@ def displayName(self):
def outputName(self):
return self.tr('Offset')

def inputLayerTypes(self):
return [QgsProcessing.TypeVectorLine]

def outputType(self):
return QgsProcessing.TypeVectorLine

@@ -25,7 +25,8 @@

__revision__ = '$Format:%H$'

from qgis.core import (QgsProcessingException,
from qgis.core import (QgsProcessing,
QgsProcessingException,
QgsProcessingParameterDefinition,
QgsProcessingParameterNumber)
from processing.algs.qgis.QgisAlgorithm import QgisFeatureBasedAlgorithm
@@ -70,6 +71,9 @@ def displayName(self):
def outputName(self):
return self.tr('Orthogonalized')

def inputLayerTypes(self):
return [QgsProcessing.TypeVectorPolygon, QgsProcessing.TypeVectorLine]

def prepareAlgorithm(self, parameters, context, feedback):
self.max_iterations = self.parameterAsInt(parameters, self.MAX_ITERATIONS, context)
self.angle_tolerance = self.parameterAsDouble(parameters, self.ANGLE_TOLERANCE, context)
@@ -67,6 +67,9 @@ def outputName(self):
def outputType(self):
return QgsProcessing.TypeVectorLine

def inputLayerTypes(self):
return [QgsProcessing.TypeVectorPolygon]

def outputWkbType(self, input_wkb_type):
return self.convertWkbToLines(input_wkb_type)

@@ -44,7 +44,6 @@
from .Aggregate import Aggregate
from .Aspect import Aspect
from .BasicStatistics import BasicStatisticsForField
from .Boundary import Boundary
from .CheckValidity import CheckValidity
from .ConcaveHull import ConcaveHull
from .CreateAttributeIndex import CreateAttributeIndex
@@ -174,7 +173,6 @@ def getAlgs(self):
Aggregate(),
Aspect(),
BasicStatisticsForField(),
Boundary(),
CheckValidity(),
ConcaveHull(),
CreateAttributeIndex(),
@@ -51,6 +51,9 @@ def outputName(self):
def outputType(self):
return QgsProcessing.TypeVectorLine

def inputLayerTypes(self):
return [QgsProcessing.TypeVectorLine]

def processFeature(self, feature, feedback):
if feature.geometry():
inGeom = feature.geometry()
@@ -86,6 +86,9 @@ def displayName(self):
def outputName(self):
return self.tr('Buffers')

def inputLayerTypes(self):
return [QgsProcessing.TypeVectorLine]

def outputType(self):
return QgsProcessing.TypeVectorPolygon

@@ -27,6 +27,7 @@

from qgis.PyQt.QtCore import QVariant
from qgis.core import (QgsField,
QgsProcessing,
QgsProcessingParameterField)
from processing.algs.qgis.QgisAlgorithm import QgisFeatureBasedAlgorithm

@@ -59,6 +60,9 @@ def displayName(self):
def outputName(self):
return self.tr('Float from text')

def inputLayerTypes(self):
return [QgsProcessing.TypeVector]

def outputFields(self, inputFields):
self.field_idx = inputFields.lookupField(self.field_name)
if self.field_idx >= 0:
@@ -665,7 +665,7 @@ tests:
name: expected/multipoint_bounds.gml
type: vector

- algorithm: qgis:boundary
- algorithm: native:boundary
name: Polygon boundary
params:
INPUT:
@@ -676,7 +676,7 @@ tests:
name: expected/poly_boundary.gml
type: vector

- algorithm: qgis:boundary
- algorithm: native:boundary
name: Multipoly boundary
params:
INPUT:
@@ -687,7 +687,7 @@ tests:
name: expected/multipoly_boundary.gml
type: vector

- algorithm: qgis:boundary
- algorithm: native:boundary
name: Line boundary
params:
INPUT:
@@ -698,7 +698,7 @@ tests:
name: expected/lines_boundary.gml
type: vector

- algorithm: qgis:boundary
- algorithm: native:boundary
name: Multiline boundary
params:
INPUT:

0 comments on commit 2951afa

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