Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Expose compatible vector layer parameter evaluation to QgsProcessingA…
…lgorithm
  • Loading branch information
nyalldawson committed Jul 8, 2017
1 parent 9e184fe commit d443bb3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
18 changes: 17 additions & 1 deletion python/core/processing/qgsprocessingalgorithm.sip
Expand Up @@ -514,7 +514,7 @@ class QgsProcessingAlgorithm

QgsProcessingFeatureSource *parameterAsSource( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const /Factory/;
%Docstring
Evaluates the parameter with matching ``definition`` to a feature source.
Evaluates the parameter with matching ``name`` to a feature source.

Sources will either be taken from ``context``'s active project, or loaded from external
sources and stored temporarily in the ``context``.
Expand All @@ -523,6 +523,22 @@ class QgsProcessingAlgorithm
:rtype: QgsProcessingFeatureSource
%End

QString parameterAsCompatibleSourceLayerPath( const QVariantMap &parameters, const QString &name,
QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat = QString( "shp" ), QgsProcessingFeedback *feedback = 0 );
%Docstring
Evaluates the parameter with matching ``name`` to a source vector layer file path of compatible format.

If the parameter is evaluated to an existing layer, and that layer is not of the format listed in the
``compatibleFormats`` argument, then the layer will first be exported to a compatible format
in a temporary location. The function will then return the path to that temporary file.

``compatibleFormats`` should consist entirely of lowercase file extensions, e.g. 'shp'.

The ``preferredFormat`` argument is used to specify to desired file extension to use when a temporary
layer export is required.
:rtype: str
%End

QgsMapLayer *parameterAsLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const;
%Docstring
Evaluates the parameter with matching ``name`` to a map layer.
Expand Down
5 changes: 5 additions & 0 deletions src/core/processing/qgsprocessingalgorithm.cpp
Expand Up @@ -503,6 +503,11 @@ QgsProcessingFeatureSource *QgsProcessingAlgorithm::parameterAsSource( const QVa
return QgsProcessingParameters::parameterAsSource( parameterDefinition( name ), parameters, context );
}

QString QgsProcessingAlgorithm::parameterAsCompatibleSourceLayerPath( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback )
{
return QgsProcessingParameters::parameterAsCompatibleSourceLayerPath( parameterDefinition( name ), parameters, context, compatibleFormats, preferredFormat, feedback );
}

QgsMapLayer *QgsProcessingAlgorithm::parameterAsLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
{
return QgsProcessingParameters::parameterAsLayer( parameterDefinition( name ), parameters, context );
Expand Down
18 changes: 17 additions & 1 deletion src/core/processing/qgsprocessingalgorithm.h
Expand Up @@ -30,6 +30,7 @@
class QgsProcessingProvider;
class QgsProcessingFeedback;
class QgsFeatureSink;
class QgsProcessingFeedback;


/**
Expand Down Expand Up @@ -485,7 +486,7 @@ class CORE_EXPORT QgsProcessingAlgorithm
const QgsFields &fields, QgsWkbTypes::Type geometryType = QgsWkbTypes::NoGeometry, const QgsCoordinateReferenceSystem &crs = QgsCoordinateReferenceSystem() ) const SIP_FACTORY;

/**
* Evaluates the parameter with matching \a definition to a feature source.
* Evaluates the parameter with matching \a name to a feature source.
*
* Sources will either be taken from \a context's active project, or loaded from external
* sources and stored temporarily in the \a context.
Expand All @@ -494,6 +495,21 @@ class CORE_EXPORT QgsProcessingAlgorithm
*/
QgsProcessingFeatureSource *parameterAsSource( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const SIP_FACTORY;

/**
* Evaluates the parameter with matching \a name to a source vector layer file path of compatible format.
*
* If the parameter is evaluated to an existing layer, and that layer is not of the format listed in the
* \a compatibleFormats argument, then the layer will first be exported to a compatible format
* in a temporary location. The function will then return the path to that temporary file.
*
* \a compatibleFormats should consist entirely of lowercase file extensions, e.g. 'shp'.
*
* The \a preferredFormat argument is used to specify to desired file extension to use when a temporary
* layer export is required.
*/
QString parameterAsCompatibleSourceLayerPath( const QVariantMap &parameters, const QString &name,
QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat = QString( "shp" ), QgsProcessingFeedback *feedback = nullptr );

/**
* Evaluates the parameter with matching \a name to a map layer.
*
Expand Down

0 comments on commit d443bb3

Please sign in to comment.