Skip to content
Permalink
Browse files

Fix GML2 after GML3 improvements

  • Loading branch information
rldhont committed Jul 7, 2017
1 parent 59d1f6d commit aa24896ce1b54a3f71d8070414d96993b10d05ed
@@ -877,12 +877,20 @@ QDomElement QgsGeometryUtils::pointsToGML2( const QgsPointSequence &points, QDom
{
QDomElement elemCoordinates = doc.createElementNS( ns, QStringLiteral( "coordinates" ) );

// coordinate separator
QString cs = ",";
// tupel separator
QString ts = " ";

elemCoordinates.setAttribute( "cs", cs );
elemCoordinates.setAttribute( "ts", ts );

QString strCoordinates;

Q_FOREACH ( const QgsPoint &p, points )
strCoordinates += qgsDoubleToString( p.x(), precision ) + ',' + qgsDoubleToString( p.y(), precision ) + ' ';
strCoordinates += qgsDoubleToString( p.x(), precision ) + cs + qgsDoubleToString( p.y(), precision ) + ts;

if ( strCoordinates.endsWith( ' ' ) )
if ( strCoordinates.endsWith( ts ) )
strCoordinates.chop( 1 ); // Remove trailing space

elemCoordinates.appendChild( doc.createTextNode( strCoordinates ) );
@@ -232,7 +232,16 @@ QDomElement QgsPoint::asGML2( QDomDocument &doc, int precision, const QString &n
{
QDomElement elemPoint = doc.createElementNS( ns, QStringLiteral( "Point" ) );
QDomElement elemCoordinates = doc.createElementNS( ns, QStringLiteral( "coordinates" ) );
QString strCoordinates = qgsDoubleToString( mX, precision ) + ',' + qgsDoubleToString( mY, precision );

// coordinate separator
QString cs = ",";
// tupel separator
QString ts = " ";

elemCoordinates.setAttribute( "cs", cs );
elemCoordinates.setAttribute( "ts", ts );

QString strCoordinates = qgsDoubleToString( mX, precision ) + cs + qgsDoubleToString( mY, precision );
elemCoordinates.appendChild( doc.createTextNode( strCoordinates ) );
elemPoint.appendChild( elemCoordinates );
return elemPoint;
@@ -616,9 +616,9 @@ void TestQgsGeometry::point()
QgsPoint exportPoint( 1, 2 );
QgsPoint exportPointFloat( 1 / 3.0, 2 / 3.0 );
QDomDocument doc( QStringLiteral( "gml" ) );
QString expectedGML2( QStringLiteral( "<Point xmlns=\"gml\"><coordinates xmlns=\"gml\">1,2</coordinates></Point>" ) );
QString expectedGML2( QStringLiteral( "<Point xmlns=\"gml\"><coordinates xmlns=\"gml\" cs=\",\" ts=\" \">1,2</coordinates></Point>" ) );
QCOMPARE( elemToString( exportPoint.asGML2( doc ) ), expectedGML2 );
QString expectedGML2prec3( QStringLiteral( "<Point xmlns=\"gml\"><coordinates xmlns=\"gml\">0.333,0.667</coordinates></Point>" ) );
QString expectedGML2prec3( QStringLiteral( "<Point xmlns=\"gml\"><coordinates xmlns=\"gml\" cs=\",\" ts=\" \">0.333,0.667</coordinates></Point>" ) );
QCOMPARE( elemToString( exportPointFloat.asGML2( doc, 3 ) ), expectedGML2prec3 );

//asGML3
@@ -1738,9 +1738,9 @@ void TestQgsGeometry::lineString()
<< QgsPoint( 1 + 1 / 3.0, 1 + 2 / 3.0 )
<< QgsPoint( 2 + 1 / 3.0, 2 + 2 / 3.0 ) );
QDomDocument doc( QStringLiteral( "gml" ) );
QString expectedGML2( QStringLiteral( "<LineString xmlns=\"gml\"><coordinates xmlns=\"gml\">31,32 41,42 51,52</coordinates></LineString>" ) );
QString expectedGML2( QStringLiteral( "<LineString xmlns=\"gml\"><coordinates xmlns=\"gml\" cs=\",\" ts=\" \">31,32 41,42 51,52</coordinates></LineString>" ) );
QCOMPARE( elemToString( exportLine.asGML2( doc ) ), expectedGML2 );
QString expectedGML2prec3( QStringLiteral( "<LineString xmlns=\"gml\"><coordinates xmlns=\"gml\">0.333,0.667 1.333,1.667 2.333,2.667</coordinates></LineString>" ) );
QString expectedGML2prec3( QStringLiteral( "<LineString xmlns=\"gml\"><coordinates xmlns=\"gml\" cs=\",\" ts=\" \">0.333,0.667 1.333,1.667 2.333,2.667</coordinates></LineString>" ) );
QCOMPARE( elemToString( exportLineFloat.asGML2( doc, 3 ) ), expectedGML2prec3 );

//asGML3
@@ -3202,11 +3202,11 @@ void TestQgsGeometry::polygon()
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>" );
QString expectedSimpleGML2( QStringLiteral( "<Polygon xmlns=\"gml\"><outerBoundaryIs xmlns=\"gml\"><LinearRing xmlns=\"gml\"><coordinates xmlns=\"gml\" cs=\",\" ts=\" \">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>" );
QString expectedSimpleGML3( QStringLiteral( "<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
@@ -3238,11 +3238,11 @@ void TestQgsGeometry::polygon()
QCOMPARE( exportPolygonFloat.asJSON( 3 ), expectedJsonPrec3 );

// as GML2
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>" );
QString expectedGML2( QStringLiteral( "<Polygon xmlns=\"gml\"><outerBoundaryIs xmlns=\"gml\"><LinearRing xmlns=\"gml\"><coordinates xmlns=\"gml\" cs=\",\" ts=\" \">0,0 0,10 10,10 10,0 0,0</coordinates></LinearRing></outerBoundaryIs>" ) );
expectedGML2 += QStringLiteral( "<innerBoundaryIs xmlns=\"gml\"><LinearRing xmlns=\"gml\"><coordinates xmlns=\"gml\" cs=\",\" ts=\" \">1,1 1,9 9,9 9,1 1,1</coordinates></LinearRing></innerBoundaryIs></Polygon>" );
QCOMPARE( elemToString( exportPolygon.asGML2( doc ) ), expectedGML2 );
QString expectedGML2prec3( QStringLiteral( "<Polygon xmlns=\"gml\"><outerBoundaryIs 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></outerBoundaryIs>" ) );
expectedGML2prec3 += QStringLiteral( "<innerBoundaryIs 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></innerBoundaryIs></Polygon>" );
QString expectedGML2prec3( QStringLiteral( "<Polygon xmlns=\"gml\"><outerBoundaryIs xmlns=\"gml\"><LinearRing xmlns=\"gml\"><coordinates xmlns=\"gml\" cs=\",\" ts=\" \">1.111,1.111 1.111,11.111 11.111,11.111 11.111,1.111 1.111,1.111</coordinates></LinearRing></outerBoundaryIs>" ) );
expectedGML2prec3 += QStringLiteral( "<innerBoundaryIs xmlns=\"gml\"><LinearRing xmlns=\"gml\"><coordinates xmlns=\"gml\" cs=\",\" ts=\" \">0.667,0.667 0.667,1.333 1.333,1.333 1.333,0.667 0.667,0.667</coordinates></LinearRing></innerBoundaryIs></Polygon>" );
QCOMPARE( elemToString( exportPolygonFloat.asGML2( doc, 3 ) ), expectedGML2prec3 );

//as GML3
@@ -14,7 +14,7 @@ Content-Type: text/xml; charset=utf-8
</gml:boundedBy>
<qgs:geometry>
<Point xmlns="http://www.opengis.net/gml" srsName="EPSG:4326">
<coordinates xmlns="http://www.opengis.net/gml">8.20349634,44.90148253</coordinates>
<coordinates xmlns="http://www.opengis.net/gml" cs="," ts=" ">8.20349634,44.90148253</coordinates>
</Point>
</qgs:geometry>
<qgs:id>1</qgs:id>
@@ -31,7 +31,7 @@ Content-Type: text/xml; charset=utf-8
</gml:boundedBy>
<qgs:geometry>
<Point xmlns="http://www.opengis.net/gml" srsName="EPSG:4326">
<coordinates xmlns="http://www.opengis.net/gml">8.20354699,44.90143568</coordinates>
<coordinates xmlns="http://www.opengis.net/gml" cs="," ts=" ">8.20354699,44.90143568</coordinates>
</Point>
</qgs:geometry>
<qgs:id>2</qgs:id>
@@ -14,7 +14,7 @@ Content-Type: text/xml; charset=utf-8
</gml:boundedBy>
<qgs:geometry>
<Point xmlns="http://www.opengis.net/gml" srsName="EPSG:4326">
<coordinates xmlns="http://www.opengis.net/gml">8.20349634,44.90148253</coordinates>
<coordinates xmlns="http://www.opengis.net/gml" cs="," ts=" ">8.20349634,44.90148253</coordinates>
</Point>
</qgs:geometry>
<qgs:id>1</qgs:id>
@@ -31,7 +31,7 @@ Content-Type: text/xml; charset=utf-8
</gml:boundedBy>
<qgs:geometry>
<Point xmlns="http://www.opengis.net/gml" srsName="EPSG:4326">
<coordinates xmlns="http://www.opengis.net/gml">8.20354699,44.90143568</coordinates>
<coordinates xmlns="http://www.opengis.net/gml" cs="," ts=" ">8.20354699,44.90143568</coordinates>
</Point>
</qgs:geometry>
<qgs:id>2</qgs:id>
@@ -48,7 +48,7 @@ Content-Type: text/xml; charset=utf-8
</gml:boundedBy>
<qgs:geometry>
<Point xmlns="http://www.opengis.net/gml" srsName="EPSG:4326">
<coordinates xmlns="http://www.opengis.net/gml">8.20345931,44.90139484</coordinates>
<coordinates xmlns="http://www.opengis.net/gml" cs="," ts=" ">8.20345931,44.90139484</coordinates>
</Point>
</qgs:geometry>
<qgs:id>3</qgs:id>
@@ -14,7 +14,7 @@ Content-Type: text/xml; charset=utf-8
</gml:boundedBy>
<qgs:geometry>
<Point xmlns="http://www.opengis.net/gml" srsName="EPSG:4326">
<coordinates xmlns="http://www.opengis.net/gml">8.20354699,44.90143568</coordinates>
<coordinates xmlns="http://www.opengis.net/gml" cs="," ts=" ">8.20354699,44.90143568</coordinates>
</Point>
</qgs:geometry>
<qgs:id>2</qgs:id>
@@ -14,7 +14,7 @@ Content-Type: text/xml; charset=utf-8
</gml:boundedBy>
<qgs:geometry>
<Point xmlns="http://www.opengis.net/gml" srsName="EPSG:4326">
<coordinates xmlns="http://www.opengis.net/gml">8.20345931,44.90139484</coordinates>
<coordinates xmlns="http://www.opengis.net/gml" cs="," ts=" ">8.20345931,44.90139484</coordinates>
</Point>
</qgs:geometry>
<qgs:id>3</qgs:id>

0 comments on commit aa24896

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