Skip to content
Permalink
Browse files

Add sourceExtent method to QgsFeatureSource

  • Loading branch information
nyalldawson committed Jun 6, 2017
1 parent 72f95e6 commit c6c20c61149e7be9238dcf79262ce00e469dee26
@@ -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

};


@@ -126,6 +126,8 @@ Bitmask of all provider's editing capabilities

virtual QgsCoordinateReferenceSystem sourceCrs() const;

virtual QgsRectangle sourceExtent() const;


virtual QString dataComment() const;
%Docstring
@@ -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
@@ -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;
}

@@ -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 * )
@@ -52,6 +52,11 @@ QgsCoordinateReferenceSystem QgsVectorDataProvider::sourceCrs() const
return crs();
}

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

QString QgsVectorDataProvider::dataComment() const
{
return QString();
@@ -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
@@ -879,6 +879,11 @@ QgsRectangle QgsVectorLayer::extent() const
return rect;
}

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

QString QgsVectorLayer::subsetString() const
{
if ( !mValid || !mDataProvider )
@@ -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.

0 comments on commit c6c20c6

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