Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix collecting geometries when one of the added geometries is already…
… multi-part

Fixes #30208
  • Loading branch information
nyalldawson committed Jun 16, 2019
1 parent 853abe0 commit e9dbea5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/core/geometry/qgsgeometry.cpp
Expand Up @@ -253,7 +253,17 @@ QgsGeometry QgsGeometry::collectGeometry( const QVector< QgsGeometry > &geometri
}
else
{
collected.addPart( g );
if ( g.isMultipart() )
{
for ( auto p = g.const_parts_begin(); p != g.const_parts_end(); ++p )
{
collected.addPart( ( *p )->clone() );
}
}
else
{
collected.addPart( g );
}
}
}
return collected;
Expand Down
25 changes: 25 additions & 0 deletions tests/src/python/test_qgsgeometry.py
Expand Up @@ -1924,6 +1924,31 @@ def testCollectGeometry(self):
wkt = geometry.asWkt()
assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt)

# collect some geometries which are already multipart
geometries = [QgsGeometry.fromWkt('LineString( 0 0, 1 1)'), QgsGeometry.fromWkt('MultiLineString((2 2, 3 3),(4 4, 5 5))')]
geometry = QgsGeometry.collectGeometry(geometries)
expwkt = "MultiLineString ((0 0, 1 1),(2 2, 3 3),(4 4, 5 5))"
wkt = geometry.asWkt()
assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt)

geometries = [QgsGeometry.fromWkt('MultiLineString((2 2, 3 3),(4 4, 5 5))'), QgsGeometry.fromWkt('LineString( 0 0, 1 1)')]
geometry = QgsGeometry.collectGeometry(geometries)
expwkt = "MultiLineString ((2 2, 3 3),(4 4, 5 5),(0 0, 1 1))"
wkt = geometry.asWkt()
assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt)

geometries = [QgsGeometry.fromWkt('Polygon((100 100, 101 100, 101 101, 100 100))'), QgsGeometry.fromWkt('MultiPolygon (((0 0, 1 0, 1 1, 0 1, 0 0)),((2 0, 3 0, 3 1, 2 1, 2 0)))')]
geometry = QgsGeometry.collectGeometry(geometries)
expwkt = "MultiPolygon (((100 100, 101 100, 101 101, 100 100)),((0 0, 1 0, 1 1, 0 1, 0 0)),((2 0, 3 0, 3 1, 2 1, 2 0)))"
wkt = geometry.asWkt()
assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt)

geometries = [QgsGeometry.fromWkt('MultiPolygon (((0 0, 1 0, 1 1, 0 1, 0 0)),((2 0, 3 0, 3 1, 2 1, 2 0)))'), QgsGeometry.fromWkt('Polygon((100 100, 101 100, 101 101, 100 100))')]
geometry = QgsGeometry.collectGeometry(geometries)
expwkt = "MultiPolygon (((0 0, 1 0, 1 1, 0 1, 0 0)),((2 0, 3 0, 3 1, 2 1, 2 0)),((100 100, 101 100, 101 101, 100 100)))"
wkt = geometry.asWkt()
assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt)

# test empty list
geometries = []
geometry = QgsGeometry.collectGeometry(geometries)
Expand Down

0 comments on commit e9dbea5

Please sign in to comment.