Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #4811 from rldhont/polygon-asgml-picking
[Geometry] Polygon::asGml: fix outer and add tests
  • Loading branch information
rldhont committed Jul 4, 2017
2 parents 0a8f755 + fe8522f commit 1aad689
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/core/geometry/qgscurvepolygon.cpp
Expand Up @@ -291,16 +291,16 @@ QDomElement QgsCurvePolygon::asGML2( QDomDocument &doc, int precision, const QSt
elemOuterBoundaryIs.appendChild( outerRing );
delete exteriorLineString;
elemPolygon.appendChild( elemOuterBoundaryIs );
QDomElement elemInnerBoundaryIs = doc.createElementNS( ns, QStringLiteral( "innerBoundaryIs" ) );
for ( int i = 0, n = numInteriorRings(); i < n; ++i )
{
QDomElement elemInnerBoundaryIs = doc.createElementNS( ns, QStringLiteral( "innerBoundaryIs" ) );
QgsLineString *interiorLineString = interiorRing( i )->curveToLine();
QDomElement innerRing = interiorLineString->asGML2( doc, precision, ns );
innerRing.toElement().setTagName( QStringLiteral( "LinearRing" ) );
elemInnerBoundaryIs.appendChild( innerRing );
delete interiorLineString;
elemPolygon.appendChild( elemInnerBoundaryIs );
}
elemPolygon.appendChild( elemInnerBoundaryIs );
return elemPolygon;
}

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

elemCurvePolygon.appendChild( elemExterior );
for ( int i = 0, n = numInteriorRings(); i < n; ++i )
{
QDomElement elemInterior = doc.createElementNS( ns, QStringLiteral( "interior" ) );
Expand Down
17 changes: 16 additions & 1 deletion tests/src/core/testqgsgeometry.cpp
Expand Up @@ -3197,6 +3197,22 @@ void TestQgsGeometry::polygon()
<< QgsPoint( QgsWkbTypes::Point, 0, 10 ) << QgsPoint( QgsWkbTypes::Point, 10, 10 )
<< QgsPoint( QgsWkbTypes::Point, 10, 0 ) << QgsPoint( QgsWkbTypes::Point, 0, 0 ) );
exportPolygon.setExteriorRing( ext );

// GML document for compare
QDomDocument doc( "gml" );

// as GML2
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>" );
QCOMPARE( elemToString( exportPolygon.asGML2( doc ) ), expectedSimpleGML2 );

//as GML3
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
QString expectedSimpleJson( "{\"type\": \"Polygon\", \"coordinates\": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0]]] }" );
QCOMPARE( exportPolygon.asJSON(), expectedSimpleJson );

ring = new QgsLineString();
ring->setPoints( QgsPointSequence() << QgsPoint( QgsWkbTypes::Point, 1, 1 )
<< QgsPoint( QgsWkbTypes::Point, 1, 9 ) << QgsPoint( QgsWkbTypes::Point, 9, 9 )
Expand All @@ -3222,7 +3238,6 @@ void TestQgsGeometry::polygon()
QCOMPARE( exportPolygonFloat.asJSON( 3 ), expectedJsonPrec3 );

// as GML2
QDomDocument doc( QStringLiteral( "gml" ) );
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>" ) );
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>" );
QCOMPARE( elemToString( exportPolygon.asGML2( doc ) ), expectedGML2 );
Expand Down

0 comments on commit 1aad689

Please sign in to comment.