diff --git a/src/core/geometry/qgscurvepolygon.cpp b/src/core/geometry/qgscurvepolygon.cpp index 13227185c55d..d68fe2f387c0 100644 --- a/src/core/geometry/qgscurvepolygon.cpp +++ b/src/core/geometry/qgscurvepolygon.cpp @@ -356,24 +356,36 @@ QDomElement QgsCurvePolygon::asGml3( QDomDocument &doc, int precision, const QSt if ( isEmpty() ) return elemCurvePolygon; - QDomElement elemExterior = doc.createElementNS( ns, QStringLiteral( "exterior" ) ); - QDomElement curveElem = exteriorRing()->asGml3( doc, precision, ns, axisOrder ); - if ( curveElem.tagName() == QLatin1String( "LineString" ) ) + const auto exportRing = [&doc, precision, &ns, axisOrder]( const QgsCurve * ring ) { - curveElem.setTagName( QStringLiteral( "LinearRing" ) ); - } - elemExterior.appendChild( curveElem ); + QDomElement ringElem = ring->asGml3( doc, precision, ns, axisOrder ); + if ( ringElem.tagName() == QLatin1String( "LineString" ) ) + { + ringElem.setTagName( QStringLiteral( "LinearRing" ) ); + } + else if ( ringElem.tagName() == QLatin1String( "CompositeCurve" ) ) + { + ringElem.setTagName( QStringLiteral( "Ring" ) ); + } + else if ( ringElem.tagName() == QLatin1String( "Curve" ) ) + { + QDomElement ringElemNew = doc.createElementNS( ns, QStringLiteral( "Ring" ) ); + QDomElement curveMemberElem = doc.createElementNS( ns, QStringLiteral( "curveMember" ) ); + ringElemNew.appendChild( curveMemberElem ); + curveMemberElem.appendChild( ringElem ); + ringElem = std::move( ringElemNew ); + } + return ringElem; + }; + + QDomElement elemExterior = doc.createElementNS( ns, QStringLiteral( "exterior" ) ); + elemExterior.appendChild( exportRing( exteriorRing() ) ); elemCurvePolygon.appendChild( elemExterior ); for ( int i = 0, n = numInteriorRings(); i < n; ++i ) { QDomElement elemInterior = doc.createElementNS( ns, QStringLiteral( "interior" ) ); - QDomElement innerRing = interiorRing( i )->asGml3( doc, precision, ns, axisOrder ); - if ( innerRing.tagName() == QLatin1String( "LineString" ) ) - { - innerRing.setTagName( QStringLiteral( "LinearRing" ) ); - } - elemInterior.appendChild( innerRing ); + elemInterior.appendChild( exportRing( interiorRing( i ) ) ); elemCurvePolygon.appendChild( elemInterior ); } return elemCurvePolygon; diff --git a/tests/src/core/geometry/testqgscurvepolygon.cpp b/tests/src/core/geometry/testqgscurvepolygon.cpp index c41cfe546b92..36f160c326ae 100644 --- a/tests/src/core/geometry/testqgscurvepolygon.cpp +++ b/tests/src/core/geometry/testqgscurvepolygon.cpp @@ -65,6 +65,7 @@ class TestQgsCurvePolygon: public QObject void testWKB(); void testWKT(); void testExport(); + void testExportOfCompoundCurveRing(); void testCast(); void removeInteriorRings_github_issue_49578(); }; @@ -1738,7 +1739,7 @@ void TestQgsCurvePolygon::testExport() QGSCOMPAREGML( elemToString( QgsCurvePolygon().asGml2( doc ) ), expectedGML2empty ); // as GML3 - QString expectedSimpleGML3( QStringLiteral( "0 0 10 1 0 11 2 0 12 1 0.5 13 0 0 10" ) ); + QString expectedSimpleGML3( QStringLiteral( "0 0 10 1 0 11 2 0 12 1 0.5 13 0 0 10" ) ); res = elemToString( exportPolygon.asGml3( doc, 2 ) ); QCOMPARE( elemToString( exportPolygon.asGml3( doc ) ), expectedSimpleGML3 ); @@ -1793,15 +1794,27 @@ void TestQgsCurvePolygon::testExport() QGSCOMPAREGML( res, expectedGML2prec2 ); // as GML3 - QString expectedGML3( QStringLiteral( "0 0 10 1 0 11 2 0 12 1 0.5 13 0 0 100 0 10 0.10000000000000001 0 11 0.20000000000000001 0 12 0.10000000000000001 0.05 13 0 0 10" ) ); + QString expectedGML3( QStringLiteral( "0 0 10 1 0 11 2 0 12 1 0.5 13 0 0 100 0 10 0.10000000000000001 0 11 0.20000000000000001 0 12 0.10000000000000001 0.05 13 0 0 10" ) ); res = elemToString( exportPolygon.asGml3( doc ) ); QCOMPARE( res, expectedGML3 ); - QString expectedGML3prec3( QStringLiteral( "0 0 10 1 0 11 2 0 12 1 0.5 13 0 0 100 0 10 0.1 0 11 0.2 0 12 0.1 0.05 13 0 0 10" ) ); + QString expectedGML3prec3( QStringLiteral( "0 0 10 1 0 11 2 0 12 1 0.5 13 0 0 100 0 10 0.1 0 11 0.2 0 12 0.1 0.05 13 0 0 10" ) ); res = elemToString( exportPolygon.asGml3( doc, 3 ) ); QCOMPARE( res, expectedGML3prec3 ); } +void TestQgsCurvePolygon::testExportOfCompoundCurveRing() +{ + QgsCurvePolygon curvePoly; + curvePoly.fromWkt( QStringLiteral( "CURVEPOLYGON (COMPOUNDCURVE ((0 -1,0 1),CIRCULARSTRING (0 1,1 0,0 -1)))" ) ); + + // as GML3 + QString expectedGML3( QStringLiteral( "0 -1 0 10 1 1 0 0 -1" ) ); + QDomDocument doc( QStringLiteral( "gml" ) ); + QString res = elemToString( curvePoly.asGml3( doc ) ); + QCOMPARE( res, expectedGML3 ); +} + void TestQgsCurvePolygon::testCast() { QVERIFY( !QgsCurvePolygon().cast( nullptr ) );