Skip to content

Commit 76d58b6

Browse files
author
wonder
committed
Fix for #707. When there were no features in provider, calculation started
with extent with null coordinates and extended it - that's reason of wrong extent git-svn-id: http://svn.osgeo.org/qgis/trunk@7128 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 6f45e29 commit 76d58b6

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/core/qgsvectorlayer.cpp

+14-12
Original file line numberDiff line numberDiff line change
@@ -1131,23 +1131,25 @@ long QgsVectorLayer::updateFeatureCount() const
11311131

11321132
void QgsVectorLayer::updateExtents()
11331133
{
1134+
mLayerExtent.setMinimal();
1135+
11341136
if(mDataProvider)
11351137
{
11361138
if(mDeletedFeatureIds.isEmpty())
11371139
{
11381140
// get the extent of the layer from the provider
1139-
QgsRect r = mDataProvider->extent();
1140-
mLayerExtent.setXmin(r.xMin());
1141-
mLayerExtent.setYmin(r.yMin());
1142-
mLayerExtent.setXmax(r.xMax());
1143-
mLayerExtent.setYmax(r.yMax());
1141+
// but only when there are some features already
1142+
if (mDataProvider->featureCount() != 0)
1143+
{
1144+
QgsRect r = mDataProvider->extent();
1145+
mLayerExtent.combineExtentWith(&r);
1146+
}
11441147
}
11451148
else
11461149
{
11471150
QgsFeature fet;
11481151
QgsRect bb;
11491152

1150-
mLayerExtent.setMinimal();
11511153
mDataProvider->select();
11521154
while (mDataProvider->getNextFeature(fet))
11531155
{
@@ -1173,6 +1175,12 @@ void QgsVectorLayer::updateExtents()
11731175
QgsRect bb = iter->geometry()->boundingBox();
11741176
mLayerExtent.combineExtentWith(&bb);
11751177
}
1178+
1179+
if (mLayerExtent.xMin() > mLayerExtent.xMax() && mLayerExtent.yMin() > mLayerExtent.yMax())
1180+
{
1181+
// special case when there are no features in provider nor any added
1182+
mLayerExtent = QgsRect(); // use rectangle with zero coordinates
1183+
}
11761184

11771185
// Send this (hopefully) up the chain to the map canvas
11781186
emit recalculateExtents();
@@ -1201,12 +1209,6 @@ void QgsVectorLayer::setSubsetString(QString subset)
12011209
mDataSource = mDataProvider->dataSourceUri();
12021210
updateExtents();
12031211

1204-
//trigger a recalculate extents request to any attached canvases
1205-
QgsDebugMsg("Subset query changed, emitting recalculateExtents() signal");
1206-
1207-
// emit the signal to inform any listeners that the extent of this
1208-
// layer has changed
1209-
emit recalculateExtents();
12101212
}
12111213

12121214

0 commit comments

Comments
 (0)