Skip to content
Permalink
Browse files

[BUGFIX] QgsCurvePolygonV2::asGML, add interior ring only if one exists

  • Loading branch information
rldhont committed Jun 28, 2017
1 parent 3130f80 commit 477cd918bf6b3034df290f60f76dcf0ccf1fdc2d
Showing with 40 additions and 15 deletions.
  1. +22 −14 src/core/geometry/qgscurvepolygonv2.cpp
  2. +18 −1 tests/src/core/testqgsgeometry.cpp
@@ -300,16 +300,20 @@ QDomElement QgsCurvePolygonV2::asGML2( QDomDocument& doc, int precision, const Q
elemOuterBoundaryIs.appendChild( outerRing );
delete exteriorLineString;
elemPolygon.appendChild( elemOuterBoundaryIs );
QDomElement elemInnerBoundaryIs = doc.createElementNS( ns, "innerBoundaryIs" );
for ( int i = 0, n = numInteriorRings(); i < n; ++i )
int n = numInteriorRings();
if ( n > 0 )
{
QgsLineStringV2* interiorLineString = interiorRing( i )->curveToLine();
QDomElement innerRing = interiorLineString->asGML2( doc, precision, ns );
innerRing.toElement().setTagName( "LinearRing" );
elemInnerBoundaryIs.appendChild( innerRing );
delete interiorLineString;
QDomElement elemInnerBoundaryIs = doc.createElementNS( ns, "innerBoundaryIs" );
for ( int i = 0; i < n; ++i )
{
QgsLineStringV2* interiorLineString = interiorRing( i )->curveToLine();
QDomElement innerRing = interiorLineString->asGML2( doc, precision, ns );
innerRing.toElement().setTagName( "LinearRing" );
elemInnerBoundaryIs.appendChild( innerRing );
delete interiorLineString;
}
elemPolygon.appendChild( elemInnerBoundaryIs );
}
elemPolygon.appendChild( elemInnerBoundaryIs );
return elemPolygon;
}

@@ -321,14 +325,18 @@ QDomElement QgsCurvePolygonV2::asGML3( QDomDocument& doc, int precision, const Q
outerRing.toElement().setTagName( "LinearRing" );
elemExterior.appendChild( outerRing );
elemCurvePolygon.appendChild( elemExterior );
QDomElement elemInterior = doc.createElementNS( ns, "interior" );
for ( int i = 0, n = numInteriorRings(); i < n; ++i )
int n = numInteriorRings();
if ( n > 0 )
{
QDomElement innerRing = interiorRing( i )->asGML2( doc, precision, ns );
innerRing.toElement().setTagName( "LinearRing" );
elemInterior.appendChild( innerRing );
QDomElement elemInterior = doc.createElementNS( ns, "interior" );
for ( int i = 0; i < n; ++i )
{
QDomElement innerRing = interiorRing( i )->asGML2( doc, precision, ns );
innerRing.toElement().setTagName( "LinearRing" );
elemInterior.appendChild( innerRing );
}
elemCurvePolygon.appendChild( elemInterior );
}
elemCurvePolygon.appendChild( elemInterior );
return elemCurvePolygon;
}

@@ -2840,12 +2840,29 @@ void TestQgsGeometry::polygonV2()
<< QgsPointV2( QgsWKBTypes::Point, 0, 10 ) << QgsPointV2( QgsWKBTypes::Point, 10, 10 )
<< QgsPointV2( QgsWKBTypes::Point, 10, 0 ) << QgsPointV2( 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\"><coordinates xmlns=\"gml\">0,0 0,10 10,10 10,0 0,0</coordinates></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 QgsLineStringV2();
ring->setPoints( QgsPointSequenceV2() << QgsPointV2( QgsWKBTypes::Point, 1, 1 )
<< QgsPointV2( QgsWKBTypes::Point, 1, 9 ) << QgsPointV2( QgsWKBTypes::Point, 9, 9 )
<< QgsPointV2( QgsWKBTypes::Point, 9, 1 ) << QgsPointV2( QgsWKBTypes::Point, 1, 1 ) );
exportPolygon.addInteriorRing( ring );

// as JSON
QString expectedJson( "{\"type\": \"Polygon\", \"coordinates\": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0]], [ [1, 1], [1, 9], [9, 9], [9, 1], [1, 1]]] }" );
QCOMPARE( exportPolygon.asJSON(), expectedJson );

@@ -2861,11 +2878,11 @@ void TestQgsGeometry::polygonV2()
<< QgsPointV2( QgsWKBTypes::Point, 4 / 3.0, 2 / 3.0 ) << QgsPointV2( QgsWKBTypes::Point, 2 / 3.0, 2 / 3.0 ) );
exportPolygonFloat.addInteriorRing( ring );

// as JSON
QString expectedJsonPrec3( "{\"type\": \"Polygon\", \"coordinates\": [[ [1.111, 1.111], [1.111, 11.111], [11.111, 11.111], [11.111, 1.111], [1.111, 1.111]], [ [0.667, 0.667], [0.667, 1.333], [1.333, 1.333], [1.333, 0.667], [0.667, 0.667]]] }" );
QCOMPARE( exportPolygonFloat.asJSON( 3 ), expectedJsonPrec3 );

// as GML2
QDomDocument doc( "gml" );
QString expectedGML2( "<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 += QString( "<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 );

0 comments on commit 477cd91

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