Skip to content

Commit c6c20c6

Browse files
committedJun 6, 2017
Add sourceExtent method to QgsFeatureSource
1 parent 72f95e6 commit c6c20c6

9 files changed

+48
-5
lines changed
 

‎python/core/qgsfeaturesource.sip

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ class QgsFeatureSource
7878
:rtype: set of QVariant
7979
%End
8080

81+
virtual QgsRectangle sourceExtent() const;
82+
%Docstring
83+
Returns the extent of all geometries from the source.
84+
The base class implementation uses a non-optimised approach of looping through
85+
all features in the source.
86+
:rtype: QgsRectangle
87+
%End
88+
8189
};
8290

8391

‎python/core/qgsvectordataprovider.sip

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ Bitmask of all provider's editing capabilities
126126

127127
virtual QgsCoordinateReferenceSystem sourceCrs() const;
128128

129+
virtual QgsRectangle sourceExtent() const;
130+
129131

130132
virtual QString dataComment() const;
131133
%Docstring

‎python/core/qgsvectorlayer.sip

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,10 +1103,8 @@ Synchronises with changes in the datasource
11031103

11041104
virtual QgsRectangle extent() const;
11051105

1106-
%Docstring
1107-
Return the extent of the layer
1108-
:rtype: QgsRectangle
1109-
%End
1106+
virtual QgsRectangle sourceExtent() const;
1107+
11101108

11111109
virtual QgsFields fields() const;
11121110
%Docstring

‎src/core/qgsfeaturesource.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,20 @@ QSet<QVariant> QgsFeatureSource::uniqueValues( int fieldIndex, int limit ) const
4040
return values;
4141
}
4242

43+
QgsRectangle QgsFeatureSource::sourceExtent() const
44+
{
45+
QgsRectangle r;
46+
47+
QgsFeatureRequest req;
48+
req.setSubsetOfAttributes( QgsAttributeList() );
49+
50+
QgsFeatureIterator it = getFeatures( req );
51+
QgsFeature f;
52+
while ( it.nextFeature( f ) )
53+
{
54+
if ( f.hasGeometry() )
55+
r.combineExtentWith( f.geometry().boundingBox() );
56+
}
57+
return r;
58+
}
59+

‎src/core/qgsfeaturesource.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ class CORE_EXPORT QgsFeatureSource
8787
*/
8888
virtual QSet<QVariant> uniqueValues( int fieldIndex, int limit = -1 ) const;
8989

90+
/**
91+
* Returns the extent of all geometries from the source.
92+
* The base class implementation uses a non-optimised approach of looping through
93+
* all features in the source.
94+
*/
95+
virtual QgsRectangle sourceExtent() const;
96+
9097
};
9198

9299
Q_DECLARE_METATYPE( QgsFeatureSource * )

‎src/core/qgsvectordataprovider.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ QgsCoordinateReferenceSystem QgsVectorDataProvider::sourceCrs() const
5252
return crs();
5353
}
5454

55+
QgsRectangle QgsVectorDataProvider::sourceExtent() const
56+
{
57+
return extent();
58+
}
59+
5560
QString QgsVectorDataProvider::dataComment() const
5661
{
5762
return QString();

‎src/core/qgsvectordataprovider.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider, public QgsFeat
159159
virtual QgsFields fields() const override = 0;
160160

161161
QgsCoordinateReferenceSystem sourceCrs() const override;
162+
QgsRectangle sourceExtent() const override;
162163

163164
/**
164165
* Return a short comment for the data that this provider is

‎src/core/qgsvectorlayer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,11 @@ QgsRectangle QgsVectorLayer::extent() const
879879
return rect;
880880
}
881881

882+
QgsRectangle QgsVectorLayer::sourceExtent() const
883+
{
884+
return extent();
885+
}
886+
882887
QString QgsVectorLayer::subsetString() const
883888
{
884889
if ( !mValid || !mDataProvider )

‎src/core/qgsvectorlayer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,8 +1077,8 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
10771077
*/
10781078
virtual QgsMapLayerRenderer *createMapRenderer( QgsRenderContext &rendererContext ) override SIP_FACTORY;
10791079

1080-
//! Return the extent of the layer
10811080
QgsRectangle extent() const override;
1081+
QgsRectangle sourceExtent() const override;
10821082

10831083
/**
10841084
* Returns the list of fields of this layer.

0 commit comments

Comments
 (0)
Please sign in to comment.