Skip to content

Commit 1aad689

Browse files
authored
Merge pull request #4811 from rldhont/polygon-asgml-picking
[Geometry] Polygon::asGml: fix outer and add tests
2 parents 0a8f755 + fe8522f commit 1aad689

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/core/geometry/qgscurvepolygon.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -291,16 +291,16 @@ QDomElement QgsCurvePolygon::asGML2( QDomDocument &doc, int precision, const QSt
291291
elemOuterBoundaryIs.appendChild( outerRing );
292292
delete exteriorLineString;
293293
elemPolygon.appendChild( elemOuterBoundaryIs );
294-
QDomElement elemInnerBoundaryIs = doc.createElementNS( ns, QStringLiteral( "innerBoundaryIs" ) );
295294
for ( int i = 0, n = numInteriorRings(); i < n; ++i )
296295
{
296+
QDomElement elemInnerBoundaryIs = doc.createElementNS( ns, QStringLiteral( "innerBoundaryIs" ) );
297297
QgsLineString *interiorLineString = interiorRing( i )->curveToLine();
298298
QDomElement innerRing = interiorLineString->asGML2( doc, precision, ns );
299299
innerRing.toElement().setTagName( QStringLiteral( "LinearRing" ) );
300300
elemInnerBoundaryIs.appendChild( innerRing );
301301
delete interiorLineString;
302+
elemPolygon.appendChild( elemInnerBoundaryIs );
302303
}
303-
elemPolygon.appendChild( elemInnerBoundaryIs );
304304
return elemPolygon;
305305
}
306306

@@ -316,7 +316,6 @@ QDomElement QgsCurvePolygon::asGML3( QDomDocument &doc, int precision, const QSt
316316
elemExterior.appendChild( curveElem );
317317
elemCurvePolygon.appendChild( elemExterior );
318318

319-
elemCurvePolygon.appendChild( elemExterior );
320319
for ( int i = 0, n = numInteriorRings(); i < n; ++i )
321320
{
322321
QDomElement elemInterior = doc.createElementNS( ns, QStringLiteral( "interior" ) );

tests/src/core/testqgsgeometry.cpp

+16-1
Original file line numberDiff line numberDiff line change
@@ -3197,6 +3197,22 @@ void TestQgsGeometry::polygon()
31973197
<< QgsPoint( QgsWkbTypes::Point, 0, 10 ) << QgsPoint( QgsWkbTypes::Point, 10, 10 )
31983198
<< QgsPoint( QgsWkbTypes::Point, 10, 0 ) << QgsPoint( QgsWkbTypes::Point, 0, 0 ) );
31993199
exportPolygon.setExteriorRing( ext );
3200+
3201+
// GML document for compare
3202+
QDomDocument doc( "gml" );
3203+
3204+
// as GML2
3205+
QString expectedSimpleGML2( "<Polygon xmlns=\"gml\"><outerBoundaryIs xmlns=\"gml\"><LinearRing xmlns=\"gml\"><coordinates xmlns=\"gml\">0,0 0,10 10,10 10,0 0,0</coordinates></LinearRing></outerBoundaryIs></Polygon>" );
3206+
QCOMPARE( elemToString( exportPolygon.asGML2( doc ) ), expectedSimpleGML2 );
3207+
3208+
//as GML3
3209+
QString expectedSimpleGML3( "<Polygon xmlns=\"gml\"><exterior xmlns=\"gml\"><LinearRing xmlns=\"gml\"><posList xmlns=\"gml\" srsDimension=\"2\">0 0 0 10 10 10 10 0 0 0</posList></LinearRing></exterior></Polygon>" );
3210+
QCOMPARE( elemToString( exportPolygon.asGML3( doc ) ), expectedSimpleGML3 );
3211+
3212+
// as JSON
3213+
QString expectedSimpleJson( "{\"type\": \"Polygon\", \"coordinates\": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0]]] }" );
3214+
QCOMPARE( exportPolygon.asJSON(), expectedSimpleJson );
3215+
32003216
ring = new QgsLineString();
32013217
ring->setPoints( QgsPointSequence() << QgsPoint( QgsWkbTypes::Point, 1, 1 )
32023218
<< QgsPoint( QgsWkbTypes::Point, 1, 9 ) << QgsPoint( QgsWkbTypes::Point, 9, 9 )
@@ -3222,7 +3238,6 @@ void TestQgsGeometry::polygon()
32223238
QCOMPARE( exportPolygonFloat.asJSON( 3 ), expectedJsonPrec3 );
32233239

32243240
// as GML2
3225-
QDomDocument doc( QStringLiteral( "gml" ) );
32263241
QString expectedGML2( QStringLiteral( "<Polygon xmlns=\"gml\"><outerBoundaryIs xmlns=\"gml\"><LinearRing xmlns=\"gml\"><coordinates xmlns=\"gml\">0,0 0,10 10,10 10,0 0,0</coordinates></LinearRing></outerBoundaryIs>" ) );
32273242
expectedGML2 += QStringLiteral( "<innerBoundaryIs xmlns=\"gml\"><LinearRing xmlns=\"gml\"><coordinates xmlns=\"gml\">1,1 1,9 9,9 9,1 1,1</coordinates></LinearRing></innerBoundaryIs></Polygon>" );
32283243
QCOMPARE( elemToString( exportPolygon.asGML2( doc ) ), expectedGML2 );

0 commit comments

Comments
 (0)