Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix GML2 after Port GML3 improvements to 2.18 branch
  • Loading branch information
rldhont committed Jul 6, 2017
1 parent d19ed1c commit 27a9985
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 19 deletions.
12 changes: 10 additions & 2 deletions src/core/geometry/qgsgeometryutils.cpp
Expand Up @@ -714,12 +714,20 @@ QDomElement QgsGeometryUtils::pointsToGML2( const QgsPointSequenceV2 &points, QD
{
QDomElement elemCoordinates = doc.createElementNS( ns, "coordinates" );

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

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

QString strCoordinates;

Q_FOREACH ( const QgsPointV2& 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 ) );
Expand Down
11 changes: 10 additions & 1 deletion src/core/geometry/qgspointv2.cpp
Expand Up @@ -213,7 +213,16 @@ QDomElement QgsPointV2::asGML2( QDomDocument& doc, int precision, const QString&
{
QDomElement elemPoint = doc.createElementNS( ns, "Point" );
QDomElement elemCoordinates = doc.createElementNS( ns, "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;
Expand Down
18 changes: 9 additions & 9 deletions tests/src/core/testqgsgeometry.cpp
Expand Up @@ -576,9 +576,9 @@ void TestQgsGeometry::pointV2()
QgsPointV2 exportPoint( 1, 2 );
QgsPointV2 exportPointFloat( 1 / 3.0, 2 / 3.0 );
QDomDocument doc( "gml" );
QString expectedGML2( "<Point xmlns=\"gml\"><coordinates xmlns=\"gml\">1,2</coordinates></Point>" );
QString expectedGML2( "<Point xmlns=\"gml\"><coordinates xmlns=\"gml\" cs=\",\" ts=\" \">1,2</coordinates></Point>" );
QCOMPARE( elemToString( exportPoint.asGML2( doc ) ), expectedGML2 );
QString expectedGML2prec3( "<Point xmlns=\"gml\"><coordinates xmlns=\"gml\">0.333,0.667</coordinates></Point>" );
QString expectedGML2prec3( "<Point xmlns=\"gml\"><coordinates xmlns=\"gml\" cs=\",\" ts=\" \">0.333,0.667</coordinates></Point>" );
QCOMPARE( elemToString( exportPointFloat.asGML2( doc, 3 ) ), expectedGML2prec3 );

//asGML3
Expand Down Expand Up @@ -1422,9 +1422,9 @@ void TestQgsGeometry::lineStringV2()
<< QgsPointV2( 1 + 1 / 3.0, 1 + 2 / 3.0 )
<< QgsPointV2( 2 + 1 / 3.0, 2 + 2 / 3.0 ) );
QDomDocument doc( "gml" );
QString expectedGML2( "<LineString xmlns=\"gml\"><coordinates xmlns=\"gml\">31,32 41,42 51,52</coordinates></LineString>" );
QString expectedGML2( "<LineString xmlns=\"gml\"><coordinates xmlns=\"gml\" cs=\",\" ts=\" \">31,32 41,42 51,52</coordinates></LineString>" );
QCOMPARE( elemToString( exportLine.asGML2( doc ) ), expectedGML2 );
QString expectedGML2prec3( "<LineString xmlns=\"gml\"><coordinates xmlns=\"gml\">0.333,0.667 1.333,1.667 2.333,2.667</coordinates></LineString>" );
QString expectedGML2prec3( "<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
Expand Down Expand Up @@ -2905,7 +2905,7 @@ void TestQgsGeometry::polygonV2()
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( "<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
Expand Down Expand Up @@ -2943,11 +2943,11 @@ void TestQgsGeometry::polygonV2()
QCOMPARE( exportPolygonFloat.asJSON( 3 ), expectedJsonPrec3 );

// as GML2
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>" );
QString expectedGML2( "<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 += QString( "<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( "<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 += QString( "<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( "<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 += QString( "<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
Expand Down
4 changes: 2 additions & 2 deletions tests/testdata/qgis_server/wfs_getfeature_limit2.txt
Expand Up @@ -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>
Expand All @@ -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>
Expand Down
6 changes: 3 additions & 3 deletions tests/testdata/qgis_server/wfs_getfeature_nobbox.txt
Expand Up @@ -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>
Expand All @@ -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>
Expand All @@ -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>
Expand Down
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion tests/testdata/qgis_server/wfs_getfeature_startindex2.txt
Expand Up @@ -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>
Expand Down

0 comments on commit 27a9985

Please sign in to comment.