Skip to content
Permalink
Browse files

[BUGFIX] QgsCurvePolygonV2::asGML3, build right GML3 polygon

  • Loading branch information
rldhont committed Jun 30, 2017
1 parent 7bc1bc4 commit b7f252bfc0ba94f44891eb0d78054abf0bf34c0e
Showing with 26 additions and 8 deletions.
  1. +21 −3 src/core/geometry/qgscurvepolygonv2.cpp
  2. +5 −5 tests/src/core/testqgsgeometry.cpp
@@ -317,15 +317,33 @@ QDomElement QgsCurvePolygonV2::asGML3( QDomDocument& doc, int precision, const Q
{
QDomElement elemCurvePolygon = doc.createElementNS( ns, "Polygon" );
QDomElement elemExterior = doc.createElementNS( ns, "exterior" );
QDomElement outerRing = exteriorRing()->asGML2( doc, precision, ns );
outerRing.toElement().setTagName( "LinearRing" );
QDomElement outerRing = exteriorRing()->asGML3( doc, precision, ns );
if ( outerRing.tagName() == QString( "Curve" ) )
{
QDomNodeList posListElements = outerRing.elementsByTagName("posList");
outerRing = doc.createElementNS( ns, "LinearRing" );
outerRing.appendChild( posListElements.at( 0 ) );
}
else
{
outerRing.setTagName( "LinearRing" );
}
elemExterior.appendChild( outerRing );
elemCurvePolygon.appendChild( elemExterior );
for ( int i = 0, n = numInteriorRings(); i < n; ++i )
{
QDomElement elemInterior = doc.createElementNS( ns, "interior" );
QDomElement innerRing = interiorRing( i )->asGML3( doc, precision, ns );
innerRing.toElement().setTagName( "LinearRing" );
if ( innerRing.tagName() == QString( "Curve" ) )
{
QDomNodeList posListElements = innerRing.elementsByTagName("posList");
innerRing = doc.createElementNS( ns, "LinearRing" );
innerRing.appendChild( posListElements.at( 0 ) );
}
else
{
innerRing.setTagName( "LinearRing" );
}
elemInterior.appendChild( innerRing );
elemCurvePolygon.appendChild( elemInterior );
}
@@ -2849,7 +2849,7 @@ void TestQgsGeometry::polygonV2()
QCOMPARE( elemToString( exportPolygon.asGML2( doc ) ), expectedSimpleGML2 );

//as GML3
QString expectedSimpleGML3( "<Polygon xmlns=\"gml\"><exterior xmlns=\"gml\"><LinearRing xmlns=\"gml\"><coordinates xmlns=\"gml\">0,0 0,10 10,10 10,0 0,0</coordinates></LinearRing></exterior></Polygon>" );
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>" );
QCOMPARE( elemToString( exportPolygon.asGML3( doc ) ), expectedSimpleGML3 );

// as JSON
@@ -2891,11 +2891,11 @@ void TestQgsGeometry::polygonV2()
QCOMPARE( elemToString( exportPolygonFloat.asGML2( doc, 3 ) ), expectedGML2prec3 );

//as GML3
QString expectedGML3( "<Polygon xmlns=\"gml\"><exterior xmlns=\"gml\"><LinearRing xmlns=\"gml\"><coordinates xmlns=\"gml\">0,0 0,10 10,10 10,0 0,0</coordinates></LinearRing></exterior>" );
expectedGML3 += QString( "<interior xmlns=\"gml\"><LinearRing xmlns=\"gml\"><coordinates xmlns=\"gml\">1,1 1,9 9,9 9,1 1,1</coordinates></LinearRing></interior></Polygon>" );
QString expectedGML3( "<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>" );
expectedGML3 += QString( "<interior xmlns=\"gml\"><LinearRing xmlns=\"gml\"><posList xmlns=\"gml\" srsDimension=\"2\">1 1 1 9 9 9 9 1 1 1</posList></LinearRing></interior></Polygon>" );
QCOMPARE( elemToString( exportPolygon.asGML3( doc ) ), expectedGML3 );
QString expectedGML3prec3( "<Polygon xmlns=\"gml\"><exterior xmlns=\"gml\"><LinearRing xmlns=\"gml\"><coordinates xmlns=\"gml\">1.111,1.111 1.111,11.111 11.111,11.111 11.111,1.111 1.111,1.111</coordinates></LinearRing></exterior>" );
expectedGML3prec3 += QString( "<interior xmlns=\"gml\"><LinearRing xmlns=\"gml\"><coordinates xmlns=\"gml\">0.667,0.667 0.667,1.333 1.333,1.333 1.333,0.667 0.667,0.667</coordinates></LinearRing></interior></Polygon>" );
QString expectedGML3prec3( "<Polygon xmlns=\"gml\"><exterior xmlns=\"gml\"><LinearRing xmlns=\"gml\"><posList xmlns=\"gml\" srsDimension=\"2\">1.111 1.111 1.111 11.111 11.111 11.111 11.111 1.111 1.111 1.111</posList></LinearRing></exterior>" );
expectedGML3prec3 += QString( "<interior xmlns=\"gml\"><LinearRing xmlns=\"gml\"><posList xmlns=\"gml\" srsDimension=\"2\">0.667 0.667 0.667 1.333 1.333 1.333 1.333 0.667 0.667 0.667</posList></LinearRing></interior></Polygon>" );
QCOMPARE( elemToString( exportPolygonFloat.asGML3( doc, 3 ) ), expectedGML3prec3 );

//removing the fourth to last vertex removes the whole ring

0 comments on commit b7f252b

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