Skip to content
Permalink
Browse files

Merge pull request #5042 from nyalldawson/algs

Port some more algs to new API
  • Loading branch information
nyalldawson committed Aug 18, 2017
2 parents 5481177 + 114f071 commit 1cded8553a1d4ccc7f5ead277c0f543ec88bdf01
Showing with 1,203 additions and 1,095 deletions.
  1. +17 −0 doc/api_break.dox
  2. +1 −1 python/analysis/interpolation/NormVecDecorator.sip
  3. +2 −2 python/analysis/interpolation/qgsgridfilewriter.sip
  4. +7 −1 python/analysis/interpolation/qgstininterpolator.sip
  5. +2 −2 python/analysis/raster/qgsrelief.sip
  6. +4 −4 python/core/processing/qgsprocessing.sip
  7. +2 −2 python/core/processing/qgsprocessingalgorithm.sip
  8. +6 −1 python/core/processing/qgsprocessingcontext.sip
  9. +4 −4 python/core/processing/qgsprocessingoutputs.sip
  10. +12 −12 python/core/processing/qgsprocessingparameters.sip
  11. +3 −3 python/plugins/processing/algs/qgis/CheckValidity.py
  12. +45 −30 python/plugins/processing/algs/qgis/Datasources2Vrt.py
  13. +1 −1 python/plugins/processing/algs/qgis/ExtractSpecificNodes.py
  14. +48 −35 python/plugins/processing/algs/qgis/HypsometricCurves.py
  15. +76 −95 python/plugins/processing/algs/qgis/IdwInterpolation.py
  16. +1 −1 python/plugins/processing/algs/qgis/Merge.py
  17. +41 −37 python/plugins/processing/algs/qgis/OrientedMinimumBoundingBox.py
  18. +1 −1 python/plugins/processing/algs/qgis/PointsLayerFromTable.py
  19. +21 −18 python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py
  20. +100 −52 python/plugins/processing/algs/qgis/RectanglesOvalsDiamondsFixed.py
  21. +134 −88 python/plugins/processing/algs/qgis/RectanglesOvalsDiamondsVariable.py
  22. +78 −88 python/plugins/processing/algs/qgis/Relief.py
  23. +17 −27 python/plugins/processing/algs/qgis/SetRasterStyle.py
  24. +14 −22 python/plugins/processing/algs/qgis/SetVectorStyle.py
  25. +94 −112 python/plugins/processing/algs/qgis/TinInterpolation.py
  26. +2 −2 python/plugins/processing/gui/BatchInputSelectionPanel.py
  27. +20 −23 python/plugins/processing/gui/EditRenderingStylesDialog.py
  28. +1 −1 python/plugins/processing/gui/FileSelectionPanel.py
  29. +5 −2 python/plugins/processing/gui/Postprocessing.py
  30. +1 −1 python/plugins/processing/gui/TestTools.py
  31. +11 −11 python/plugins/processing/gui/wrappers.py
  32. +1 −2 python/plugins/processing/modeler/ModelerGraphicItem.py
  33. +44 −25 python/plugins/processing/modeler/ModelerParameterDefinitionDialog.py
  34. +0 −3 python/plugins/processing/script/snippets.py
  35. +184 −180 python/plugins/processing/tests/testdata/qgis_algorithm_tests.yaml
  36. +0 −2 src/analysis/interpolation/CloughTocherInterpolator.cc
  37. +38 −22 src/analysis/interpolation/CloughTocherInterpolator.h
  38. +9 −13 src/analysis/interpolation/DualEdgeTriangulation.cc
  39. +0 −1 src/analysis/interpolation/MathUtils.cc
  40. +6 −18 src/analysis/interpolation/NormVecDecorator.cc
  41. +2 −2 src/analysis/interpolation/NormVecDecorator.h
  42. +5 −13 src/analysis/interpolation/qgsgridfilewriter.cpp
  43. +3 −2 src/analysis/interpolation/qgsgridfilewriter.h
  44. +9 −25 src/analysis/interpolation/qgstininterpolator.cpp
  45. +9 −2 src/analysis/interpolation/qgstininterpolator.h
  46. +10 −13 src/analysis/raster/qgsrelief.cpp
  47. +3 −3 src/analysis/raster/qgsrelief.h
  48. +2 −2 src/core/processing/models/qgsprocessingmodelalgorithm.cpp
  49. +4 −4 src/core/processing/qgsnativealgorithms.cpp
  50. +1 −1 src/core/processing/qgsnativealgorithms.h
  51. +6 −6 src/core/processing/qgsprocessing.h
  52. +1 −1 src/core/processing/qgsprocessingalgorithm.h
  53. +5 −1 src/core/processing/qgsprocessingcontext.h
  54. +3 −3 src/core/processing/qgsprocessingoutputs.cpp
  55. +4 −4 src/core/processing/qgsprocessingoutputs.h
  56. +32 −26 src/core/processing/qgsprocessingparameters.cpp
  57. +14 −14 src/core/processing/qgsprocessingparameters.h
  58. +5 −2 src/core/processing/qgsprocessingutils.cpp
  59. +1 −1 src/server/qgsinterpolationlayerbuilder.cpp
  60. +31 −25 tests/src/core/testqgsprocessing.cpp
@@ -1348,6 +1348,13 @@ QgsGraduatedRenderer {#qgis_api_break_3_0_QgsGraduatedRenderer}
- setInvertedColorRamp() and invertedColorRamp() functions are gone, QgsColorRamp now responsible for invert
- createRenderer() and updateColorRamp()'s inverted parameter is gone


QgsGridFileWriter {#qgis_api_break_3_0_QgsGridFileWriter}
-----------------

- writeFile() now takes an optional QgsFeedback argument instead of using a QProgressDialog


QgsGroupWMSDataDialog {#qgis_api_break_3_0_QgsGroupWMSDataDialog}
---------------------

@@ -1973,6 +1980,11 @@ QgsRelation {#qgis_api_break_3_0_QgsRelation}
- `setRelationName()` has been renamed to `QgsRelation::setName()`
- `setRelationId()` has been renamed to `QgsRelation::setId()`

QgsRelief {#qgis_api_break_3_0_QgsRelief}
---------

- processRaster() now uses a QgsFeedback object instead of a QProgressDialog


QgsRenderChecker {#qgis_api_break_3_0_QgsRenderChecker}
----------------
@@ -2309,6 +2321,11 @@ QgsSymbolsListWidget {#qgis_api_break_3_0_QgsSymbolsListWidget}
- expressionContext(), setExpressionContext(), setMapCanvas() and mapCanvas() have been removed in favor of setContext()/context()


QgsTINInterpolator {#qgis_api_break_3_0_QgsTINInterpolator}
------------------

- The constructor takes a QgsFeedback argument instead of using a QProgressDialog.

QgsTolerance {#qgis_api_break_3_0_QgsTolerance}
------------

@@ -59,7 +59,7 @@ Eliminates the horizontal triangles by swapping or by insertion of new points. I
Estimates the first derivative a point. Return true in case of succes and false otherwise
:rtype: bool
%End
bool estimateFirstDerivatives( QProgressDialog *d = 0 );
bool estimateFirstDerivatives( QgsFeedback *feedback = 0 );
%Docstring
This method adds the functionality of estimating normals at the data points. Return true in the case of success and false otherwise
:rtype: bool
@@ -20,10 +20,10 @@ class QgsGridFileWriter
QgsGridFileWriter( QgsInterpolator *i, const QString &outputPath, const QgsRectangle &extent, int nCols, int nRows, double cellSizeX, double cellSizeY );


int writeFile( bool showProgressDialog = false );
int writeFile( QgsFeedback *feedback = 0 );
%Docstring
Writes the grid file.
\param showProgressDialog shows a dialog with the possibility to cancel
\param feedback optional feedback object for progress reports and cancelation support
:return: 0 in case of success*
:rtype: int
%End
@@ -25,7 +25,13 @@ class QgsTINInterpolator: QgsInterpolator
Linear,
CloughTocher
};
QgsTINInterpolator( const QList<QgsInterpolator::LayerData> &inputData, TINInterpolation interpolation = Linear, bool showProgressDialog = false );

QgsTINInterpolator( const QList<QgsInterpolator::LayerData> &inputData, TINInterpolation interpolation = Linear, QgsFeedback *feedback = 0 );
%Docstring
Constructor for QgsTINInterpolator.
The ``feedback`` object specifies an optional QgsFeedback object for progress reports and cancelation support.
Ownership of ``feedback`` is not transferred and callers must ensure that it exists for the lifetime of this object.
%End
~QgsTINInterpolator();

virtual int interpolatePoint( double x, double y, double &result );
@@ -32,10 +32,10 @@ class QgsRelief
~QgsRelief();


int processRaster( QProgressDialog *p );
int processRaster( QgsFeedback *feedback = 0 );
%Docstring
Starts the calculation, reads from mInputFile and stores the result in mOutputFile
\param p progress dialog that receives update and that is checked for abort. 0 if no progress bar is needed.
\param feedback feedback object that receives update and that is checked for cancelation.
:return: 0 in case of success*
:rtype: int
%End
@@ -26,16 +26,16 @@ class QgsProcessing
%End
public:

enum LayerType
enum SourceType
{
TypeAny,
TypeVectorAny,
TypeMapLayer,
TypeVectorAnyGeometry,
TypeVectorPoint,
TypeVectorLine,
TypeVectorPolygon,
TypeRaster,
TypeFile,
TypeTable,
TypeVector,
};


@@ -760,11 +760,11 @@ class QgsProcessingFeatureBasedAlgorithm : QgsProcessingAlgorithm
:rtype: str
%End

virtual QgsProcessing::LayerType outputLayerType() const;
virtual QgsProcessing::SourceType outputLayerType() const;
%Docstring
Returns the layer type for layers generated by this algorithm, if
this is possible to determine in advance.
:rtype: QgsProcessing.LayerType
:rtype: QgsProcessing.SourceType
%End

virtual QgsWkbTypes::Type outputWkbType( QgsWkbTypes::Type inputWkbType ) const;
@@ -92,14 +92,19 @@ class QgsProcessingContext
struct LayerDetails
{

LayerDetails( const QString &name, QgsProject *project );
LayerDetails( const QString &name, QgsProject *project, const QString &outputName = QString() );
%Docstring
Constructor for LayerDetails.
%End

QString name;
%Docstring
Friendly name for layer, to use when loading layer into project.
%End

QString outputName;
%Docstring
Associated output name from algorithm which generated the layer.
%End

QgsProject *project;
@@ -108,7 +108,7 @@ class QgsProcessingOutputVectorLayer : QgsProcessingOutputDefinition
%End
public:

QgsProcessingOutputVectorLayer( const QString &name, const QString &description = QString(), QgsProcessing::LayerType type = QgsProcessing::TypeVectorAny );
QgsProcessingOutputVectorLayer( const QString &name, const QString &description = QString(), QgsProcessing::SourceType type = QgsProcessing::TypeVectorAnyGeometry );
%Docstring
Constructor for QgsProcessingOutputVectorLayer.
%End
@@ -120,14 +120,14 @@ class QgsProcessingOutputVectorLayer : QgsProcessingOutputDefinition
%End
virtual QString type() const;

QgsProcessing::LayerType dataType() const;
QgsProcessing::SourceType dataType() const;
%Docstring
Returns the layer type for the output layer.
.. seealso:: setDataType()
:rtype: QgsProcessing.LayerType
:rtype: QgsProcessing.SourceType
%End

void setDataType( QgsProcessing::LayerType type );
void setDataType( QgsProcessing::SourceType type );
%Docstring
Sets the layer ``type`` for the output layer.
.. seealso:: dataType()
@@ -975,7 +975,7 @@ class QgsProcessingParameterMultipleLayers : QgsProcessingParameterDefinition
%End
public:

QgsProcessingParameterMultipleLayers( const QString &name, const QString &description = QString(), QgsProcessing::LayerType layerType = QgsProcessing::TypeVectorAny,
QgsProcessingParameterMultipleLayers( const QString &name, const QString &description = QString(), QgsProcessing::SourceType layerType = QgsProcessing::TypeVectorAnyGeometry,
const QVariant &defaultValue = QVariant(),
bool optional = false );
%Docstring
@@ -997,14 +997,14 @@ class QgsProcessingParameterMultipleLayers : QgsProcessingParameterDefinition
virtual QString asScriptCode() const;


QgsProcessing::LayerType layerType() const;
QgsProcessing::SourceType layerType() const;
%Docstring
Returns the layer type for layers acceptable by the parameter.
.. seealso:: setLayerType()
:rtype: QgsProcessing.LayerType
:rtype: QgsProcessing.SourceType
%End

void setLayerType( QgsProcessing::LayerType type );
void setLayerType( QgsProcessing::SourceType type );
%Docstring
Sets the layer ``type`` for layers acceptable by the parameter.
.. seealso:: layerType()
@@ -1733,7 +1733,7 @@ class QgsProcessingParameterFeatureSink : QgsProcessingDestinationParameter
%End
public:

QgsProcessingParameterFeatureSink( const QString &name, const QString &description = QString(), QgsProcessing::LayerType type = QgsProcessing::TypeVectorAny, const QVariant &defaultValue = QVariant(),
QgsProcessingParameterFeatureSink( const QString &name, const QString &description = QString(), QgsProcessing::SourceType type = QgsProcessing::TypeVectorAnyGeometry, const QVariant &defaultValue = QVariant(),
bool optional = false );
%Docstring
Constructor for QgsProcessingParameterFeatureSink.
@@ -1758,11 +1758,11 @@ class QgsProcessingParameterFeatureSink : QgsProcessingDestinationParameter
virtual QString defaultFileExtension() const;


QgsProcessing::LayerType dataType() const;
QgsProcessing::SourceType dataType() const;
%Docstring
Returns the layer type for sinks associated with the parameter.
.. seealso:: setDataType()
:rtype: QgsProcessing.LayerType
:rtype: QgsProcessing.SourceType
%End

bool hasGeometry() const;
@@ -1772,7 +1772,7 @@ class QgsProcessingParameterFeatureSink : QgsProcessingDestinationParameter
:rtype: bool
%End

void setDataType( QgsProcessing::LayerType type );
void setDataType( QgsProcessing::SourceType type );
%Docstring
Sets the layer ``type`` for the sinks associated with the parameter.
.. seealso:: dataType()
@@ -1812,7 +1812,7 @@ class QgsProcessingParameterVectorDestination : QgsProcessingDestinationParamete
%End
public:

QgsProcessingParameterVectorDestination( const QString &name, const QString &description = QString(), QgsProcessing::LayerType type = QgsProcessing::TypeVectorAny, const QVariant &defaultValue = QVariant(),
QgsProcessingParameterVectorDestination( const QString &name, const QString &description = QString(), QgsProcessing::SourceType type = QgsProcessing::TypeVectorAnyGeometry, const QVariant &defaultValue = QVariant(),
bool optional = false );
%Docstring
Constructor for QgsProcessingParameterVectorDestination.
@@ -1837,11 +1837,11 @@ class QgsProcessingParameterVectorDestination : QgsProcessingDestinationParamete
virtual QString defaultFileExtension() const;


QgsProcessing::LayerType dataType() const;
QgsProcessing::SourceType dataType() const;
%Docstring
Returns the layer type for this created vector layer.
.. seealso:: setDataType()
:rtype: QgsProcessing.LayerType
:rtype: QgsProcessing.SourceType
%End

bool hasGeometry() const;
@@ -1851,7 +1851,7 @@ class QgsProcessingParameterVectorDestination : QgsProcessingDestinationParamete
:rtype: bool
%End

void setDataType( QgsProcessing::LayerType type );
void setDataType( QgsProcessing::SourceType type );
%Docstring
Sets the layer ``type`` for the created vector layer.
.. seealso:: dataType()
@@ -81,13 +81,13 @@ def initAlgorithm(self, config=None):
self.addParameter(QgsProcessingParameterEnum(self.METHOD,
self.tr('Method'), self.methods))

self.addParameter(QgsProcessingParameterFeatureSink(self.VALID_OUTPUT, self.tr('Valid output'), QgsProcessing.TypeVectorAny, '', True))
self.addParameter(QgsProcessingParameterFeatureSink(self.VALID_OUTPUT, self.tr('Valid output'), QgsProcessing.TypeVectorAnyGeometry, '', True))
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.addParameter(QgsProcessingParameterFeatureSink(self.INVALID_OUTPUT, self.tr('Invalid output'), QgsProcessing.TypeVectorAnyGeometry, '', True))
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.addParameter(QgsProcessingParameterFeatureSink(self.ERROR_OUTPUT, self.tr('Error output'), QgsProcessing.TypeVectorAnyGeometry, '', True))
self.addOutput(QgsProcessingOutputNumber(self.ERROR_COUNT, self.tr('Count of errors')))

def name(self):
@@ -31,21 +31,20 @@

from osgeo import ogr
from qgis.core import (QgsProcessingFeedback,
QgsApplication)
from processing.tools import dataobjects
QgsProcessingParameterMultipleLayers,
QgsProcessingParameterBoolean,
QgsProcessing,
QgsProcessingParameterVectorDestination,
QgsProcessingOutputString,
QgsProcessingException)
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from processing.core.parameters import ParameterMultipleInput
from processing.core.parameters import ParameterBoolean
from processing.core.outputs import OutputFile
from processing.core.outputs import OutputString


class Datasources2Vrt(QgisAlgorithm):
DATASOURCES = 'DATASOURCES'
INPUT = 'INPUT'
UNIONED = 'UNIONED'

VRT_FILE = 'VRT_FILE'
OUTPUT = 'OUTPUT'
VRT_STRING = 'VRT_STRING'

def group(self):
@@ -55,17 +54,32 @@ def __init__(self):
super().__init__()

def initAlgorithm(self, config=None):
self.addParameter(ParameterMultipleInput(self.DATASOURCES,
self.tr('Input datasources'),
dataobjects.TYPE_TABLE))
self.addParameter(ParameterBoolean(self.UNIONED,
self.tr('Create "unioned" VRT'),
default=False))

self.addOutput(OutputFile(self.VRT_FILE,
self.tr('Virtual vector'), ext='vrt'))
self.addOutput(OutputString(self.VRT_STRING,
self.tr('Virtual string')))
self.addParameter(QgsProcessingParameterMultipleLayers(self.INPUT,
self.tr('Input datasources'),
QgsProcessing.TypeVector))
self.addParameter(QgsProcessingParameterBoolean(self.UNIONED,
self.tr('Create "unioned" VRT'),
defaultValue=False))

class ParameterVectorVrtDestination(QgsProcessingParameterVectorDestination):

def __init__(self, name, description):
super().__init__(name, description)

def clone(self):
copy = ParameterVectorVrtDestination(self.name(), self.description())
return copy

def type(self):
return 'vrt_vector_destination'

def defaultFileExtension(self):
return 'vrt'

self.addParameter(ParameterVectorVrtDestination(self.OUTPUT,
self.tr('Virtual vector')))
self.addOutput(QgsProcessingOutputString(self.VRT_STRING,
self.tr('Virtual string')))

def name(self):
return 'buildvirtualvector'
@@ -74,20 +88,17 @@ def displayName(self):
return self.tr('Build virtual vector')

def processAlgorithm(self, parameters, context, feedback):
input_layers = self.getParameterValue(self.DATASOURCES)
unioned = self.getParameterValue(self.UNIONED)
vrtPath = self.getOutputValue(self.VRT_FILE)

layers = input_layers.split(';')
input_layers = self.parameterAsLayerList(parameters, self.INPUT, context)
unioned = self.parameterAsBool(parameters, self.UNIONED, context)
vrtPath = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)

vrtString = self.mergeDataSources2Vrt(layers,
vrtString = self.mergeDataSources2Vrt(input_layers,
vrtPath,
union=unioned,
relative=False,
schema=False,
feedback=feedback)

self.setOutputValue(self.VRT_STRING, vrtString)
return {self.OUTPUT: vrtPath, self.VRT_STRING: vrtString}

def mergeDataSources2Vrt(self, dataSources, outFile, union=False, relative=False,
schema=False, feedback=None):
@@ -107,12 +118,16 @@ def mergeDataSources2Vrt(self, dataSources, outFile, union=False, relative=False
vrt += '<OGRVRTUnionLayer name="UnionedLayer">'

total = 100.0 / len(dataSources) if dataSources else 1
for current, inFile in enumerate(dataSources):
for current, layer in enumerate(dataSources):
if feedback.isCanceled():
break

feedback.setProgress(int(current * total))

inFile = layer.source()
srcDS = ogr.Open(inFile, 0)
if srcDS is None:
raise GeoAlgorithmExecutionException(
raise QgsProcessingException(
self.tr('Invalid datasource: {}'.format(inFile)))

if schema:

0 comments on commit 1cded85

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