diff --git a/src/core/geometry/qgscurvepolygon.cpp b/src/core/geometry/qgscurvepolygon.cpp index df86ada4c00..9ddc13df46b 100644 --- a/src/core/geometry/qgscurvepolygon.cpp +++ b/src/core/geometry/qgscurvepolygon.cpp @@ -305,13 +305,16 @@ QString QgsCurvePolygon::asWkt( int precision ) const } for ( const QgsCurve *curve : mInteriorRings ) { - QString childWkt = curve->asWkt( precision ); - if ( qgsgeometry_cast( curve ) ) + if ( !curve->isEmpty() ) { - // Type names of linear geometries are omitted - childWkt = childWkt.mid( childWkt.indexOf( '(' ) ); + QString childWkt = curve->asWkt( precision ); + if ( qgsgeometry_cast( curve ) ) + { + // Type names of linear geometries are omitted + childWkt = childWkt.mid( childWkt.indexOf( '(' ) ); + } + wkt += childWkt + ','; } - wkt += childWkt + ','; } if ( wkt.endsWith( ',' ) ) { diff --git a/src/core/geometry/qgspolygon.cpp b/src/core/geometry/qgspolygon.cpp index 494fce95811..64a1a0d71ef 100644 --- a/src/core/geometry/qgspolygon.cpp +++ b/src/core/geometry/qgspolygon.cpp @@ -206,19 +206,22 @@ QString QgsPolygon::asWkt( int precision ) const } for ( const QgsCurve *curve : mInteriorRings ) { - QString childWkt; - if ( ! qgsgeometry_cast( curve ) ) + if ( !curve->isEmpty() ) { - std::unique_ptr line( curve->curveToLine() ); - childWkt = line->asWkt( precision ); + QString childWkt; + if ( ! qgsgeometry_cast( curve ) ) + { + std::unique_ptr line( curve->curveToLine() ); + childWkt = line->asWkt( precision ); + } + else + { + childWkt = curve->asWkt( precision ); + } + // Type names of linear geometries are omitted + childWkt = childWkt.mid( childWkt.indexOf( '(' ) ); + wkt += childWkt + ','; } - else - { - childWkt = curve->asWkt( precision ); - } - // Type names of linear geometries are omitted - childWkt = childWkt.mid( childWkt.indexOf( '(' ) ); - wkt += childWkt + ','; } if ( wkt.endsWith( ',' ) ) { diff --git a/tests/src/core/geometry/testqgscurvepolygon.cpp b/tests/src/core/geometry/testqgscurvepolygon.cpp index 58cf00763e1..f351107ee4d 100644 --- a/tests/src/core/geometry/testqgscurvepolygon.cpp +++ b/tests/src/core/geometry/testqgscurvepolygon.cpp @@ -1731,6 +1731,17 @@ void TestQgsCurvePolygon::testWKT() QVERIFY( !poly2.is3D() ); QVERIFY( !poly2.isMeasure() ); QCOMPARE( poly2.wkbType(), Qgis::WkbType::CurvePolygon ); + + // Test WKT export with empty interior ring + QgsCurvePolygon poly3; + QgsCircularString *ext2 = new QgsCircularString(); + ext2->setPoints( QgsPointSequence() << QgsPoint( Qgis::WkbType::PointZM, 0, 0, 10, 1 ) + << QgsPoint( Qgis::WkbType::PointZM, 10, 0, 11, 2 ) << QgsPoint( Qgis::WkbType::PointZM, 10, 10, 12, 3 ) + << QgsPoint( Qgis::WkbType::PointZM, 0, 10, 13, 4 ) << QgsPoint( Qgis::WkbType::PointZM, 0, 0, 10, 1 ) ); + poly3.setExteriorRing( ext2 ); + poly3.addInteriorRing( new QgsCircularString() ); + wkt = poly3.asWkt(); + QCOMPARE( wkt, QStringLiteral( "CurvePolygonZM (CircularStringZM (0 0 10 1, 10 0 11 2, 10 10 12 3, 0 10 13 4, 0 0 10 1))" ) ); } void TestQgsCurvePolygon::testExport() diff --git a/tests/src/core/geometry/testqgspolygon.cpp b/tests/src/core/geometry/testqgspolygon.cpp index ee6686a0854..b473ff9cf22 100644 --- a/tests/src/core/geometry/testqgspolygon.cpp +++ b/tests/src/core/geometry/testqgspolygon.cpp @@ -2854,6 +2854,19 @@ void TestQgsPolygon::toFromWKT() pl3.addInteriorRing( compound ); wkt = pl3.asWkt(); QCOMPARE( wkt, QStringLiteral( "Polygon ((0 0, 0 10, 10 10, 10 0, 0 0),(1 1, 1 9, 9 9, 9 1, 1 1))" ) ); + + // Test WKT export with empty interior ring + QgsPolygon pl4; + QgsLineString *ext4 = new QgsLineString(); + ext4->setPoints( QgsPointSequence() << QgsPoint( Qgis::WkbType::Point, 0, 0 ) + << QgsPoint( Qgis::WkbType::Point, 0, 10 ) + << QgsPoint( Qgis::WkbType::Point, 10, 10 ) + << QgsPoint( Qgis::WkbType::Point, 10, 0 ) + << QgsPoint( Qgis::WkbType::Point, 0, 0 ) ); + pl4.setExteriorRing( ext4 ); + pl4.addInteriorRing( new QgsLineString() ); + wkt = pl4.asWkt(); + QCOMPARE( wkt, QStringLiteral( "Polygon ((0 0, 0 10, 10 10, 10 0, 0 0))" ) ); } void TestQgsPolygon::exportImport()