Add sourceExtent method to QgsFeatureSource

This commit is contained in:
Nyall Dawson 2017-06-06 17:26:07 +10:00
parent 72f95e6f1a
commit c6c20c6114
9 changed files with 48 additions and 5 deletions

View File

@ -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
};

View File

@ -126,6 +126,8 @@ Bitmask of all provider's editing capabilities
virtual QgsCoordinateReferenceSystem sourceCrs() const;
virtual QgsRectangle sourceExtent() const;
virtual QString dataComment() const;
%Docstring

View File

@ -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

View File

@ -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;
}

View File

@ -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 * )

View File

@ -52,6 +52,11 @@ QgsCoordinateReferenceSystem QgsVectorDataProvider::sourceCrs() const
return crs();
}
QgsRectangle QgsVectorDataProvider::sourceExtent() const
{
return extent();
}
QString QgsVectorDataProvider::dataComment() const
{
return QString();

View File

@ -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

View File

@ -879,6 +879,11 @@ QgsRectangle QgsVectorLayer::extent() const
return rect;
}
QgsRectangle QgsVectorLayer::sourceExtent() const
{
return extent();
}
QString QgsVectorLayer::subsetString() const
{
if ( !mValid || !mDataProvider )

View File

@ -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.