@@ -2840,12 +2840,29 @@ void TestQgsGeometry::polygonV2()
2840
2840
<< QgsPointV2 ( QgsWKBTypes::Point , 0 , 10 ) << QgsPointV2 ( QgsWKBTypes::Point , 10 , 10 )
2841
2841
<< QgsPointV2 ( QgsWKBTypes::Point , 10 , 0 ) << QgsPointV2 ( QgsWKBTypes::Point , 0 , 0 ) );
2842
2842
exportPolygon.setExteriorRing ( ext );
2843
+
2844
+ // GML document for compare
2845
+ QDomDocument doc ( " gml" );
2846
+
2847
+ // as GML2
2848
+ 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>" );
2849
+ QCOMPARE ( elemToString ( exportPolygon.asGML2 ( doc ) ), expectedSimpleGML2 );
2850
+
2851
+ // as GML3
2852
+ 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>" );
2853
+ QCOMPARE ( elemToString ( exportPolygon.asGML3 ( doc ) ), expectedSimpleGML3 );
2854
+
2855
+ // as JSON
2856
+ QString expectedSimpleJson ( " {\" type\" : \" Polygon\" , \" coordinates\" : [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0]]] }" );
2857
+ QCOMPARE ( exportPolygon.asJSON (), expectedSimpleJson );
2858
+
2843
2859
ring = new QgsLineStringV2 ();
2844
2860
ring->setPoints ( QgsPointSequenceV2 () << QgsPointV2 ( QgsWKBTypes::Point , 1 , 1 )
2845
2861
<< QgsPointV2 ( QgsWKBTypes::Point , 1 , 9 ) << QgsPointV2 ( QgsWKBTypes::Point , 9 , 9 )
2846
2862
<< QgsPointV2 ( QgsWKBTypes::Point , 9 , 1 ) << QgsPointV2 ( QgsWKBTypes::Point , 1 , 1 ) );
2847
2863
exportPolygon.addInteriorRing ( ring );
2848
2864
2865
+ // as JSON
2849
2866
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]]] }" );
2850
2867
QCOMPARE ( exportPolygon.asJSON (), expectedJson );
2851
2868
@@ -2861,11 +2878,11 @@ void TestQgsGeometry::polygonV2()
2861
2878
<< QgsPointV2 ( QgsWKBTypes::Point , 4 / 3.0 , 2 / 3.0 ) << QgsPointV2 ( QgsWKBTypes::Point , 2 / 3.0 , 2 / 3.0 ) );
2862
2879
exportPolygonFloat.addInteriorRing ( ring );
2863
2880
2881
+ // as JSON
2864
2882
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]]] }" );
2865
2883
QCOMPARE ( exportPolygonFloat.asJSON ( 3 ), expectedJsonPrec3 );
2866
2884
2867
2885
// as GML2
2868
- QDomDocument doc ( " gml" );
2869
2886
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>" );
2870
2887
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>" );
2871
2888
QCOMPARE ( elemToString ( exportPolygon.asGML2 ( doc ) ), expectedGML2 );
0 commit comments