Skip to content
Permalink
Browse files

Export QgsProcessingFeatureSource to Python

  • Loading branch information
nyalldawson committed Jun 26, 2017
1 parent 255fe0b commit 3fb1b4809d84c496606d50332f209a0d28cc7f3f
@@ -376,15 +376,15 @@ class QgsProcessingAlgorithm
:rtype: QgsFeatureSink
%End

QgsFeatureSource *parameterAsSource( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const /Factory/;
QgsProcessingFeatureSource *parameterAsSource( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const /Factory/;
%Docstring
Evaluates the parameter with matching ``definition`` 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``.

This function creates a new object and the caller takes responsibility for deleting the returned object.
:rtype: QgsFeatureSource
:rtype: QgsProcessingFeatureSource
%End

QgsMapLayer *parameterAsLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const;
@@ -436,15 +436,15 @@ class QgsProcessingParameters
:rtype: QgsFeatureSink
%End

static QgsFeatureSource *parameterAsSource( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context ) /Factory/;
static QgsProcessingFeatureSource *parameterAsSource( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context ) /Factory/;
%Docstring
Evaluates the parameter with matching ``definition`` 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``.

This function creates a new object and the caller takes responsibility for deleting the returned object.
:rtype: QgsFeatureSource
:rtype: QgsProcessingFeatureSource
%End

static QgsMapLayer *parameterAsLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context );
@@ -160,6 +160,59 @@ class QgsProcessingUtils

};

class QgsProcessingFeatureSource : QgsFeatureSource
{
%Docstring
QgsFeatureSource subclass which proxies methods to an underlying QgsFeatureSource, modifying
results according to the settings in a QgsProcessingContext.
.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgsprocessingutils.h"
%End
public:

enum Flag
{
FlagSkipGeometryValidityChecks,
};
typedef QFlags<QgsProcessingFeatureSource::Flag> Flags;


QgsProcessingFeatureSource( QgsFeatureSource *originalSource, const QgsProcessingContext &context, bool ownsOriginalSource = false );
%Docstring
Constructor for QgsProcessingFeatureSource, accepting an original feature source ``originalSource``
and processing ``context``.
Ownership of ``originalSource`` is dictated by ``ownsOriginalSource``. If ``ownsOriginalSource`` is false,
ownership is not transferred, and callers must ensure that ``originalSource`` exists for the lifetime of this object.
If ``ownsOriginalSource`` is true, then this object will take ownership of ``originalSource``.
%End

~QgsProcessingFeatureSource();

QgsFeatureIterator getFeatures( const QgsFeatureRequest &request, Flags flags ) const;
%Docstring
Returns an iterator for the features in the source, respecting the supplied feature ``flags``.
An optional ``request`` can be used to optimise the returned
iterator, eg by restricting the returned attributes or geometry.
:rtype: QgsFeatureIterator
%End

virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest &request = QgsFeatureRequest() ) const;

virtual QgsCoordinateReferenceSystem sourceCrs() const;

virtual QgsFields fields() const;

virtual QgsWkbTypes::Type wkbType() const;

virtual long featureCount() const;

virtual QString sourceName() const;


};



@@ -374,7 +374,7 @@ QgsFeatureSink *QgsProcessingAlgorithm::parameterAsSink( const QVariantMap &para
return QgsProcessingParameters::parameterAsSink( parameterDefinition( name ), parameters, fields, geometryType, crs, context, destinationIdentifier );
}

QgsFeatureSource *QgsProcessingAlgorithm::parameterAsSource( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
QgsProcessingFeatureSource *QgsProcessingAlgorithm::parameterAsSource( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
{
return QgsProcessingParameters::parameterAsSource( parameterDefinition( name ), parameters, context );
}
@@ -370,7 +370,7 @@ class CORE_EXPORT QgsProcessingAlgorithm
*
* This function creates a new object and the caller takes responsibility for deleting the returned object.
*/
QgsFeatureSource *parameterAsSource( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const SIP_FACTORY;
QgsProcessingFeatureSource *parameterAsSource( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const SIP_FACTORY;

/**
* Evaluates the parameter with matching \a name to a map layer.
@@ -258,7 +258,7 @@ QgsFeatureSink *QgsProcessingParameters::parameterAsSink( const QgsProcessingPar
return sink.release();
}

QgsFeatureSource *QgsProcessingParameters::parameterAsSource( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
QgsProcessingFeatureSource *QgsProcessingParameters::parameterAsSource( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
{
if ( !definition )
return nullptr;
@@ -30,6 +30,7 @@ class QgsRasterLayer;
class QgsVectorLayer;
class QgsFeatureSink;
class QgsFeatureSource;
class QgsProcessingFeatureSource;
class QgsProcessingOutputDefinition;

/**
@@ -479,7 +480,7 @@ class CORE_EXPORT QgsProcessingParameters
*
* This function creates a new object and the caller takes responsibility for deleting the returned object.
*/
static QgsFeatureSource *parameterAsSource( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context ) SIP_FACTORY;
static QgsProcessingFeatureSource *parameterAsSource( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context ) SIP_FACTORY;

/**
* Evaluates the parameter with matching \a definition to a map layer.
@@ -219,17 +219,14 @@ class CORE_EXPORT QgsProcessingUtils

};

#ifndef SIP_RUN

/**
* \class QgsProcessingFeatureSource
* \ingroup core
* QgsFeatureSource subclass which proxies methods to an underlying QgsFeatureSource, modifying
* results according to the settings in a QgsProcessingContext.
* \note not available in Python bindings
* \since QGIS 3.0
*/
class QgsProcessingFeatureSource : public QgsFeatureSource
class CORE_EXPORT QgsProcessingFeatureSource : public QgsFeatureSource
{
public:

@@ -261,8 +258,6 @@ class QgsProcessingFeatureSource : public QgsFeatureSource

};

#endif

#endif // QGSPROCESSINGUTILS_H


0 comments on commit 3fb1b48

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