Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 2951afa
Show file tree
Hide file tree
Showing 22 changed files with 233 additions and 100 deletions.
8 changes: 8 additions & 0 deletions python/core/processing/qgsprocessingalgorithm.sip
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions python/plugins/processing/algs/qgis/AddTableField.py
Expand Up @@ -27,6 +27,7 @@

from qgis.PyQt.QtCore import QVariant
from qgis.core import (QgsField,
QgsProcessing,
QgsProcessingParameterString,
QgsProcessingParameterNumber,
QgsProcessingParameterEnum)
Expand Down Expand Up @@ -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)
Expand Down
81 changes: 0 additions & 81 deletions python/plugins/processing/algs/qgis/Boundary.py

This file was deleted.

6 changes: 5 additions & 1 deletion python/plugins/processing/algs/qgis/DeleteColumn.py
Expand Up @@ -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


Expand All @@ -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'

Expand Down
6 changes: 5 additions & 1 deletion python/plugins/processing/algs/qgis/DeleteHoles.py
Expand Up @@ -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


Expand Down Expand Up @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion python/plugins/processing/algs/qgis/DensifyGeometries.py
Expand Up @@ -28,7 +28,8 @@

import os

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

from processing.algs.qgis.QgisAlgorithm import QgisFeatureBasedAlgorithm

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

Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion python/plugins/processing/algs/qgis/ExtendLines.py
Expand Up @@ -26,7 +26,8 @@
__revision__ = '$Format:%H$'

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


Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions python/plugins/processing/algs/qgis/FieldsMapper.py
Expand Up @@ -30,6 +30,7 @@
QgsExpression,
QgsField,
QgsFields,
QgsProcessing,
QgsProcessingException,
QgsProcessingParameterDefinition)

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

Expand Down
3 changes: 3 additions & 0 deletions python/plugins/processing/algs/qgis/LinesToPolygons.py
Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions python/plugins/processing/algs/qgis/OffsetLine.py
Expand Up @@ -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

Expand Down
6 changes: 5 additions & 1 deletion python/plugins/processing/algs/qgis/Orthogonalize.py
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions python/plugins/processing/algs/qgis/PolygonsToLines.py
Expand Up @@ -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)

Expand Down
2 changes: 0 additions & 2 deletions python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py
Expand Up @@ -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
Expand Down Expand Up @@ -174,7 +173,6 @@ def getAlgs(self):
Aggregate(),
Aspect(),
BasicStatisticsForField(),
Boundary(),
CheckValidity(),
ConcaveHull(),
CreateAttributeIndex(),
Expand Down
3 changes: 3 additions & 0 deletions python/plugins/processing/algs/qgis/ReverseLineDirection.py
Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions python/plugins/processing/algs/qgis/SingleSidedBuffer.py
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions python/plugins/processing/algs/qgis/TextToFloat.py
Expand Up @@ -27,6 +27,7 @@

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

Expand Down Expand Up @@ -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:
Expand Down
Expand Up @@ -665,7 +665,7 @@ tests:
name: expected/multipoint_bounds.gml
type: vector

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

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

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

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

0 comments on commit 2951afa

Please sign in to comment.