Skip to content

Commit bca3553

Browse files
committed
Fix #651 (zoom to layer with one point does not work)
1 parent 48b099c commit bca3553

File tree

6 files changed

+20
-4
lines changed

6 files changed

+20
-4
lines changed

python/core/qgsrectangle.sip

+4
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ class QgsRectangle
7777
//! expand the rectangle so that covers both the original rectangle and the given point
7878
void combineExtentWith( double x, double y );
7979
//! test if rectangle is empty
80+
//! Empty rectangle may still be non-null if it contains valid information (e.g. bounding box of a point)
8081
bool isEmpty() const;
82+
//! test if the rectangle has all coordinates zero. Null rectangle is also an empty rectangle.
83+
//! @note added in 2.4
84+
bool isNull() const;
8185
//! returns string representation in Wkt form
8286
QString asWktCoordinates() const;
8387
//! returns string representation as WKT Polygon

src/core/qgsmaprenderer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ void QgsMapRenderer::updateFullExtent()
929929
QgsDebugMsg( "Updating extent using " + lyr->name() );
930930
QgsDebugMsg( "Input extent: " + lyr->extent().toString() );
931931

932-
if ( lyr->extent().isEmpty() )
932+
if ( lyr->extent().isNull() )
933933
{
934934
++it;
935935
continue;

src/core/qgsmapsettings.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ QgsRectangle QgsMapSettings::fullExtent() const
430430
QgsDebugMsg( "Updating extent using " + lyr->name() );
431431
QgsDebugMsg( "Input extent: " + lyr->extent().toString() );
432432

433-
if ( lyr->extent().isEmpty() )
433+
if ( lyr->extent().isNull() )
434434
{
435435
it++;
436436
continue;

src/core/qgsrectangle.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@ bool QgsRectangle::isEmpty() const
194194
return xmax <= xmin || ymax <= ymin;
195195
}
196196

197+
bool QgsRectangle::isNull() const
198+
{
199+
return xmin == 0 && xmax == 0 && ymin == 0 && ymax == 0;
200+
}
201+
197202
QString QgsRectangle::asWktCoordinates() const
198203
{
199204
QString rep =

src/core/qgsrectangle.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,12 @@ class CORE_EXPORT QgsRectangle
9999
void combineExtentWith( QgsRectangle *rect );
100100
//! expand the rectangle so that covers both the original rectangle and the given point
101101
void combineExtentWith( double x, double y );
102-
//! test if rectangle is empty
102+
//! test if rectangle is empty.
103+
//! Empty rectangle may still be non-null if it contains valid information (e.g. bounding box of a point)
103104
bool isEmpty() const;
105+
//! test if the rectangle has all coordinates zero. Null rectangle is also an empty rectangle.
106+
//! @note added in 2.4
107+
bool isNull() const;
104108
//! returns string representation in Wkt form
105109
QString asWktCoordinates() const;
106110
//! returns string representation as WKT Polygon

src/gui/layertree/qgslayertreeviewdefaultactions.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ void QgsLayerTreeViewDefaultActions::zoomToLayers( QgsMapCanvas* canvas, const Q
200200

201201
QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer*>( layer );
202202

203+
if ( vLayer->geometryType() == QGis::NoGeometry )
204+
continue;
205+
203206
if ( layerExtent.isEmpty() && layer->type() == QgsMapLayer::VectorLayer )
204207
{
205208
qobject_cast<QgsVectorLayer*>( layer )->updateExtents();
@@ -216,7 +219,7 @@ void QgsLayerTreeViewDefaultActions::zoomToLayers( QgsMapCanvas* canvas, const Q
216219
extent.combineExtentWith( &layerExtent );
217220
}
218221

219-
if ( extent.isEmpty() )
222+
if ( extent.isNull() )
220223
return;
221224

222225
// Increase bounding box with 5%, so that layer is a bit inside the borders

0 commit comments

Comments
 (0)