Skip to content

Commit

Permalink
Add sourceExtent method to QgsFeatureSource
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 6, 2017
1 parent 72f95e6 commit c6c20c6
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 5 deletions.
8 changes: 8 additions & 0 deletions python/core/qgsfeaturesource.sip
Expand Up @@ -78,6 +78,14 @@ class QgsFeatureSource
:rtype: set of QVariant
%End

virtual QgsRectangle sourceExtent() const;
%Docstring
Returns the extent of all geometries from the source.
The base class implementation uses a non-optimised approach of looping through
all features in the source.
:rtype: QgsRectangle
%End

};


Expand Down
2 changes: 2 additions & 0 deletions python/core/qgsvectordataprovider.sip
Expand Up @@ -126,6 +126,8 @@ Bitmask of all provider's editing capabilities

virtual QgsCoordinateReferenceSystem sourceCrs() const;

virtual QgsRectangle sourceExtent() const;


virtual QString dataComment() const;
%Docstring
Expand Down
6 changes: 2 additions & 4 deletions python/core/qgsvectorlayer.sip
Expand Up @@ -1103,10 +1103,8 @@ Synchronises with changes in the datasource

virtual QgsRectangle extent() const;

%Docstring
Return the extent of the layer
:rtype: QgsRectangle
%End
virtual QgsRectangle sourceExtent() const;


virtual QgsFields fields() const;
%Docstring
Expand Down
17 changes: 17 additions & 0 deletions src/core/qgsfeaturesource.cpp
Expand Up @@ -40,3 +40,20 @@ QSet<QVariant> QgsFeatureSource::uniqueValues( int fieldIndex, int limit ) const
return values;
}

QgsRectangle QgsFeatureSource::sourceExtent() const
{
QgsRectangle r;

QgsFeatureRequest req;
req.setSubsetOfAttributes( QgsAttributeList() );

QgsFeatureIterator it = getFeatures( req );
QgsFeature f;
while ( it.nextFeature( f ) )
{
if ( f.hasGeometry() )
r.combineExtentWith( f.geometry().boundingBox() );
}
return r;
}

7 changes: 7 additions & 0 deletions src/core/qgsfeaturesource.h
Expand Up @@ -87,6 +87,13 @@ class CORE_EXPORT QgsFeatureSource
*/
virtual QSet<QVariant> uniqueValues( int fieldIndex, int limit = -1 ) const;

/**
* Returns the extent of all geometries from the source.
* The base class implementation uses a non-optimised approach of looping through
* all features in the source.
*/
virtual QgsRectangle sourceExtent() const;

};

Q_DECLARE_METATYPE( QgsFeatureSource * )
Expand Down
5 changes: 5 additions & 0 deletions src/core/qgsvectordataprovider.cpp
Expand Up @@ -52,6 +52,11 @@ QgsCoordinateReferenceSystem QgsVectorDataProvider::sourceCrs() const
return crs();
}

QgsRectangle QgsVectorDataProvider::sourceExtent() const
{
return extent();
}

QString QgsVectorDataProvider::dataComment() const
{
return QString();
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsvectordataprovider.h
Expand Up @@ -159,6 +159,7 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider, public QgsFeat
virtual QgsFields fields() const override = 0;

QgsCoordinateReferenceSystem sourceCrs() const override;
QgsRectangle sourceExtent() const override;

/**
* Return a short comment for the data that this provider is
Expand Down
5 changes: 5 additions & 0 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -879,6 +879,11 @@ QgsRectangle QgsVectorLayer::extent() const
return rect;
}

QgsRectangle QgsVectorLayer::sourceExtent() const
{
return extent();
}

QString QgsVectorLayer::subsetString() const
{
if ( !mValid || !mDataProvider )
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsvectorlayer.h
Expand Up @@ -1077,8 +1077,8 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
*/
virtual QgsMapLayerRenderer *createMapRenderer( QgsRenderContext &rendererContext ) override SIP_FACTORY;

//! Return the extent of the layer
QgsRectangle extent() const override;
QgsRectangle sourceExtent() const override;

/**
* Returns the list of fields of this layer.
Expand Down

0 comments on commit c6c20c6

Please sign in to comment.