Skip to content
Permalink
Browse files

Fix adding parts to curved polygon types fails

  • Loading branch information
nyalldawson committed Mar 6, 2018
1 parent 8a063df commit 93f805cd09ee4972ca2ae67cea3671224149c42f
Showing with 20 additions and 2 deletions.
  1. +4 −2 src/core/geometry/qgsgeometryeditutils.cpp
  2. +16 −0 tests/src/python/test_qgsgeometry.py
@@ -137,11 +137,13 @@ QgsGeometry::OperationResult QgsGeometryEditUtils::addPart( QgsAbstractGeometry
poly->setExteriorRing( curve );
added = geomCollection->addGeometry( poly.release() );
}
else if ( QgsWkbTypes::flatType( part->wkbType() ) == QgsWkbTypes::Polygon )
else if ( QgsWkbTypes::flatType( part->wkbType() ) == QgsWkbTypes::Polygon
|| QgsWkbTypes::flatType( part->wkbType() ) == QgsWkbTypes::CurvePolygon )
{
added = geomCollection->addGeometry( part.release() );
}
else if ( QgsWkbTypes::flatType( part->wkbType() ) == QgsWkbTypes::MultiPolygon )
else if ( QgsWkbTypes::flatType( part->wkbType() ) == QgsWkbTypes::MultiPolygon
|| QgsWkbTypes::flatType( part->wkbType() ) == QgsWkbTypes::MultiSurface )
{
std::unique_ptr<QgsGeometryCollection> parts( static_cast<QgsGeometryCollection *>( part.release() ) );

@@ -1509,6 +1509,22 @@ def testAddPart(self):
wkt = polygon.asWkt()
assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt)

# test adding a part to a multisurface
geom = QgsGeometry.fromWkt('MultiSurface(((0 0,0 1,1 1,0 0)))')
g2 = QgsGeometry.fromWkt('CurvePolygon ((0 0,0 1,1 1,0 0))')
geom.addPart(g2.get().clone())
wkt = geom.asWkt()
expwkt = 'MultiSurface (Polygon ((0 0, 0 1, 1 1, 0 0)),CurvePolygon ((0 0, 0 1, 1 1, 0 0)))'
assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt)

# test adding a multisurface to a multisurface
geom = QgsGeometry.fromWkt('MultiSurface(((20 0,20 1,21 1,20 0)))')
g2 = QgsGeometry.fromWkt('MultiSurface (Polygon ((0 0, 0 1, 1 1, 0 0)),CurvePolygon ((0 0, 0 1, 1 1, 0 0)))')
geom.addPart(g2.get().clone())
wkt = geom.asWkt()
expwkt = 'MultiSurface (Polygon ((20 0, 20 1, 21 1, 20 0)),Polygon ((0 0, 0 1, 1 1, 0 0)),CurvePolygon ((0 0, 0 1, 1 1, 0 0)))'
assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt)

# Test adding parts to empty geometry, should become first part
empty = QgsGeometry()
# if not default type specified, addPart should fail

0 comments on commit 93f805c

Please sign in to comment.
You can’t perform that action at this time.