Skip to content

Commit

Permalink
Fix for #707. When there were no features in provider, calculation st…
Browse files Browse the repository at this point in the history
…arted

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
  • Loading branch information
wonder committed Aug 6, 2007
1 parent 6f45e29 commit 76d58b6
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -1131,23 +1131,25 @@ long QgsVectorLayer::updateFeatureCount() const

void QgsVectorLayer::updateExtents()
{
mLayerExtent.setMinimal();

if(mDataProvider)
{
if(mDeletedFeatureIds.isEmpty())
{
// get the extent of the layer from the provider
QgsRect r = mDataProvider->extent();
mLayerExtent.setXmin(r.xMin());
mLayerExtent.setYmin(r.yMin());
mLayerExtent.setXmax(r.xMax());
mLayerExtent.setYmax(r.yMax());
// but only when there are some features already
if (mDataProvider->featureCount() != 0)
{
QgsRect r = mDataProvider->extent();
mLayerExtent.combineExtentWith(&r);
}
}
else
{
QgsFeature fet;
QgsRect bb;

mLayerExtent.setMinimal();
mDataProvider->select();
while (mDataProvider->getNextFeature(fet))
{
Expand All @@ -1173,6 +1175,12 @@ void QgsVectorLayer::updateExtents()
QgsRect bb = iter->geometry()->boundingBox();
mLayerExtent.combineExtentWith(&bb);
}

if (mLayerExtent.xMin() > mLayerExtent.xMax() && mLayerExtent.yMin() > mLayerExtent.yMax())
{
// special case when there are no features in provider nor any added
mLayerExtent = QgsRect(); // use rectangle with zero coordinates
}

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

//trigger a recalculate extents request to any attached canvases
QgsDebugMsg("Subset query changed, emitting recalculateExtents() signal");

// emit the signal to inform any listeners that the extent of this
// layer has changed
emit recalculateExtents();
}


Expand Down

0 comments on commit 76d58b6

Please sign in to comment.