Skip to content

Commit

Permalink
Fix (0,0) points are ignored when calculating the bounding box for a …
Browse files Browse the repository at this point in the history
…multipoint geometry
  • Loading branch information
github-actions[bot] authored and nirvn committed Apr 10, 2020
1 parent 95ae4b4 commit 9dcc9dc
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/core/geometry/qgsgeometrycollection.cpp
Expand Up @@ -477,8 +477,28 @@ QgsRectangle QgsGeometryCollection::calculateBoundingBox() const
QgsRectangle bbox = mGeometries.at( 0 )->boundingBox();
for ( int i = 1; i < mGeometries.size(); ++i )
{
if ( mGeometries.at( i )->isEmpty() )
continue;

QgsRectangle geomBox = mGeometries.at( i )->boundingBox();
bbox.combineExtentWith( geomBox );
if ( bbox.isNull() )
{
// workaround treatment of a QgsRectangle(0,0,0,0) as a "null"/invalid rectangle
// if bbox is null, then the first geometry must have returned a bounding box of (0,0,0,0)
// so just manually include that as a point... ew.
geomBox.combineExtentWith( QPointF( 0, 0 ) );
bbox = geomBox;
}
else if ( geomBox.isNull() )
{
// ...as above... this part must have a bounding box of (0,0,0,0).
// if we try to combine the extent with this "null" box it will just be ignored.
bbox.combineExtentWith( QPointF( 0, 0 ) );
}
else
{
bbox.combineExtentWith( geomBox );
}
}
return bbox;
}
Expand Down
15 changes: 15 additions & 0 deletions tests/src/core/testqgsgeometry.cpp
Expand Up @@ -12259,6 +12259,21 @@ void TestQgsGeometry::multiPoint()
pCast2.fromWkt( QStringLiteral( "MultiPointZM(PointZM(0 1 1 2))" ) );
QVERIFY( QgsMultiPoint().cast( &pCast2 ) );

// bounding box
QgsMultiPoint boundingBox;
boundingBox.addGeometry( new QgsPoint( 0, 0 ) );
QCOMPARE( boundingBox.boundingBox(), QgsRectangle( 0, 0, 0, 0 ) );
boundingBox.addGeometry( new QgsPoint( 1, 2 ) );
QCOMPARE( boundingBox.boundingBox(), QgsRectangle( 0, 0, 1, 2 ) );
QgsMultiPoint boundingBox2;
QCOMPARE( boundingBox2.boundingBox(), QgsRectangle( 0, 0, 0, 0 ) );
boundingBox2.addGeometry( new QgsPoint( 1, 2 ) );
QCOMPARE( boundingBox2.boundingBox(), QgsRectangle( 1, 2, 1, 2 ) );
boundingBox2.addGeometry( new QgsPoint( 10, 3 ) );
QCOMPARE( boundingBox2.boundingBox(), QgsRectangle( 1, 2, 10, 3 ) );
boundingBox2.addGeometry( new QgsPoint( 0, 0 ) );
QCOMPARE( boundingBox2.boundingBox(), QgsRectangle( 0, 0, 10, 3 ) );

//boundary

//multipoints have no boundary defined
Expand Down

0 comments on commit 9dcc9dc

Please sign in to comment.