Skip to content

Commit

Permalink
Add crs, fields, wkbType and featureCount to QgsFeatureSource
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 25, 2017
1 parent 8bfeb8f commit 4647662
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 8 deletions.
38 changes: 38 additions & 0 deletions python/core/qgsfeaturesource.sip
Expand Up @@ -9,6 +9,7 @@




class QgsFeatureSource
{
%Docstring
Expand All @@ -32,8 +33,45 @@ class QgsFeatureSource
:rtype: QgsFeatureIterator
%End

virtual QgsCoordinateReferenceSystem sourceCrs() const = 0;
%Docstring
Returns the coordinate reference system for features in the source.
:rtype: QgsCoordinateReferenceSystem
%End

virtual QgsFields fields() const = 0;
%Docstring
Returns the fields associated with features in the source.
:rtype: QgsFields
%End

virtual QgsWkbTypes::Type wkbType() const = 0;
%Docstring
Returns the geometry type for features returned by this source.
:rtype: QgsWkbTypes.Type
%End


int __len__() const;
%Docstring
Returns the number of features contained in the source, or -1
if the feature count is unknown.
:rtype: int
%End
%MethodCode
sipRes = sipCpp->featureCount();
%End

virtual long featureCount() const = 0;
%Docstring
Returns the number of features contained in the source, or -1
if the feature count is unknown.
:rtype: long
%End

};


/************************************************************************
* This file has been generated automatically from *
* *
Expand Down
3 changes: 3 additions & 0 deletions python/core/qgsvectordataprovider.sip
Expand Up @@ -124,6 +124,9 @@ Bitmask of all provider's editing capabilities
:rtype: QgsFields
%End

virtual QgsCoordinateReferenceSystem sourceCrs() const;


virtual QString dataComment() const;
%Docstring
Return a short comment for the data that this provider is
Expand Down
11 changes: 8 additions & 3 deletions python/core/qgsvectorlayer.sip
Expand Up @@ -685,7 +685,8 @@ Returns true if this is a geometry layer and false in case of NoGeometry (table
:rtype: bool
%End

QgsWkbTypes::Type wkbType() const;
virtual QgsWkbTypes::Type wkbType() const;

%Docstring
Returns the WKBType or WKBUnknown in case of error
:rtype: QgsWkbTypes.Type
Expand All @@ -697,6 +698,9 @@ Return the provider type for this layer
:rtype: str
%End

virtual QgsCoordinateReferenceSystem sourceCrs() const;


virtual bool readXml( const QDomNode &layer_node, const QgsReadWriteContext &context );
%Docstring
Reads vector layer specific state from project file Dom node.
Expand Down Expand Up @@ -1104,7 +1108,7 @@ Return the extent of the layer
:rtype: QgsRectangle
%End

QgsFields fields() const;
virtual QgsFields fields() const;
%Docstring
Returns the list of fields of this layer.
This also includes fields which have not yet been saved to the provider.
Expand Down Expand Up @@ -1157,7 +1161,8 @@ Returns list of attributes making up the primary key
:rtype: long
%End

long featureCount() const;
virtual long featureCount() const;

%Docstring
Returns feature count including changes which have not yet been committed
If you need only the count of committed features call this method on this layer's provider.
Expand Down
40 changes: 38 additions & 2 deletions src/core/qgsfeaturesource.h
Expand Up @@ -20,8 +20,11 @@

#include "qgis_core.h"
#include "qgis.h"
#include "qgsfeature.h"
#include "qgsfeatureiterator.h"

class QgsFeatureIterator;
class QgsFeatureRequest;
class QgsCoordinateReferenceSystem;
class QgsFields;

/**
* \class QgsFeatureSource
Expand All @@ -43,6 +46,39 @@ class CORE_EXPORT QgsFeatureSource
*/
virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest &request = QgsFeatureRequest() ) const = 0;

/**
* Returns the coordinate reference system for features in the source.
*/
virtual QgsCoordinateReferenceSystem sourceCrs() const = 0;

/**
* Returns the fields associated with features in the source.
*/
virtual QgsFields fields() const = 0;

/**
* Returns the geometry type for features returned by this source.
*/
virtual QgsWkbTypes::Type wkbType() const = 0;

#ifdef SIP_RUN

/**
* Returns the number of features contained in the source, or -1
* if the feature count is unknown.
*/
int __len__() const;
% MethodCode
sipRes = sipCpp->featureCount();
% End
#endif

/**
* Returns the number of features contained in the source, or -1
* if the feature count is unknown.
*/
virtual long featureCount() const = 0;

};

#endif // QGSFEATURESOURCE_H
5 changes: 5 additions & 0 deletions src/core/qgsvectordataprovider.cpp
Expand Up @@ -47,6 +47,11 @@ QString QgsVectorDataProvider::storageType() const
return QStringLiteral( "Generic vector file" );
}

QgsCoordinateReferenceSystem QgsVectorDataProvider::sourceCrs() const
{
return crs();
}

QString QgsVectorDataProvider::dataComment() const
{
return QString();
Expand Down
2 changes: 2 additions & 0 deletions src/core/qgsvectordataprovider.h
Expand Up @@ -158,6 +158,8 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider, public QgsFeat
*/
virtual QgsFields fields() const = 0;

QgsCoordinateReferenceSystem sourceCrs() const override;

/**
* Return a short comment for the data that this provider is
* providing access to (e.g. the comment for postgres table).
Expand Down
5 changes: 5 additions & 0 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -309,6 +309,11 @@ QString QgsVectorLayer::providerType() const
return mProviderKey;
}

QgsCoordinateReferenceSystem QgsVectorLayer::sourceCrs() const
{
return crs();
}

void QgsVectorLayer::reload()
{
if ( mDataProvider )
Expand Down
8 changes: 5 additions & 3 deletions src/core/qgsvectorlayer.h
Expand Up @@ -691,11 +691,13 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
bool hasGeometryType() const;

//! Returns the WKBType or WKBUnknown in case of error
QgsWkbTypes::Type wkbType() const;
QgsWkbTypes::Type wkbType() const override;

//! Return the provider type for this layer
QString providerType() const;

QgsCoordinateReferenceSystem sourceCrs() const override;

/** Reads vector layer specific state from project file Dom node.
* \note Called by QgsMapLayer::readXml().
*/
Expand Down Expand Up @@ -1083,7 +1085,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
*
* \returns A list of fields
*/
inline QgsFields fields() const { return mFields; }
inline QgsFields fields() const override { return mFields; }

/**
* Returns the list of fields of this layer.
Expand Down Expand Up @@ -1125,7 +1127,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
* Returns feature count including changes which have not yet been committed
* If you need only the count of committed features call this method on this layer's provider.
*/
long featureCount() const;
long featureCount() const override;

/** Make layer read-only (editing disabled) or not
* \returns false if the layer is in editing yet
Expand Down

0 comments on commit 4647662

Please sign in to comment.