Skip to content
Permalink
Browse files

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

  • Loading branch information
rldhont committed Jun 30, 2017
1 parent 392b638 commit 6e52f1b1e74121898544b6fbf47f735943a7ea9b
Showing with 37 additions and 10 deletions.
  1. +19 −9 src/core/geometry/qgscurvepolygonv2.cpp
  2. +18 −1 tests/src/core/testqgsgeometry.cpp
@@ -303,37 +303,47 @@ 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 )
{
QDomElement elemInnerBoundaryIs = doc.createElementNS( ns, "innerBoundaryIs" );
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;
}

QDomElement QgsCurvePolygonV2::asGML3( QDomDocument& doc, int precision, const QString& ns ) const
{
QDomElement elemCurvePolygon = doc.createElementNS( ns, "Polygon" );
QDomElement elemExterior = doc.createElementNS( ns, "exterior" );
QDomElement curveElem = exteriorRing()->asGML3( doc, precision, ns );
if ( curveElem.tagName() == "LineString" )
QDomElement outerRing = exteriorRing()->asGML3( doc, precision, ns );
if ( outerRing.tagName() == QString( "Curve" ) )
{
curveElem.setTagName( "LinearRing" );
QDomNodeList posListElements = outerRing.elementsByTagName( "posList" );
outerRing = doc.createElementNS( ns, "LinearRing" );
outerRing.appendChild( posListElements.at( 0 ) );
}
elemExterior.appendChild( curveElem );
elemCurvePolygon.appendChild( elemExterior );

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 );
if ( innerRing.tagName() == "LineString" )
if ( innerRing.tagName() == QString( "Curve" ) )
{
QDomNodeList posListElements = innerRing.elementsByTagName( "posList" );
innerRing = doc.createElementNS( ns, "LinearRing" );
innerRing.appendChild( posListElements.at( 0 ) );
}
else
{
innerRing.setTagName( "LinearRing" );
}
@@ -2900,12 +2900,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\"><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 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 );

@@ -2921,11 +2938,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 6e52f1b

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