Skip to content

Commit

Permalink
Merge pull request #5042 from nyalldawson/algs
Browse files Browse the repository at this point in the history
Port some more algs to new API
  • Loading branch information
nyalldawson committed Aug 18, 2017
2 parents 5481177 + 114f071 commit 1cded85
Show file tree
Hide file tree
Showing 60 changed files with 1,203 additions and 1,095 deletions.
17 changes: 17 additions & 0 deletions doc/api_break.dox
Expand Up @@ -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}
---------------------

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

Expand Down
2 changes: 1 addition & 1 deletion python/analysis/interpolation/NormVecDecorator.sip
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions python/analysis/interpolation/qgsgridfilewriter.sip
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion python/analysis/interpolation/qgstininterpolator.sip
Expand Up @@ -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 );
Expand Down
4 changes: 2 additions & 2 deletions python/analysis/raster/qgsrelief.sip
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions python/core/processing/qgsprocessing.sip
Expand Up @@ -26,16 +26,16 @@ class QgsProcessing
%End
public:

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


Expand Down
4 changes: 2 additions & 2 deletions python/core/processing/qgsprocessingalgorithm.sip
Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion python/core/processing/qgsprocessingcontext.sip
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions python/core/processing/qgsprocessingoutputs.sip
Expand Up @@ -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
Expand All @@ -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()
Expand Down
24 changes: 12 additions & 12 deletions python/core/processing/qgsprocessingparameters.sip
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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.
Expand All @@ -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;
Expand All @@ -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()
Expand Down Expand Up @@ -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.
Expand All @@ -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;
Expand All @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions python/plugins/processing/algs/qgis/CheckValidity.py
Expand Up @@ -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):
Expand Down
75 changes: 45 additions & 30 deletions python/plugins/processing/algs/qgis/Datasources2Vrt.py
Expand Up @@ -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):
Expand All @@ -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'
Expand All @@ -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):
Expand All @@ -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:
Expand Down

0 comments on commit 1cded85

Please sign in to comment.