Skip to content

Commit 7443431

Browse files
committed
Fix incorrect GML from QgsPointV2::asGML3
Also finish unit tests for QgsPointV2 and mark as a critical class
1 parent b10e708 commit 7443431

File tree

3 files changed

+81
-5
lines changed

3 files changed

+81
-5
lines changed

src/core/geometry/qgspointv2.cpp

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
#include "qgswkbptr.h"
2525
#include <QPainter>
2626

27+
/***************************************************************************
28+
* This class is considered CRITICAL and any change MUST be accompanied with
29+
* full unit tests.
30+
* See details in QEP #17
31+
****************************************************************************/
32+
2733
QgsPointV2::QgsPointV2( double x, double y )
2834
: QgsAbstractGeometryV2()
2935
, mX( x )
@@ -65,6 +71,12 @@ QgsPointV2::QgsPointV2( QgsWKBTypes::Type type, double x, double y, double z, do
6571
mWkbType = type;
6672
}
6773

74+
/***************************************************************************
75+
* This class is considered CRITICAL and any change MUST be accompanied with
76+
* full unit tests.
77+
* See details in QEP #17
78+
****************************************************************************/
79+
6880
bool QgsPointV2::operator==( const QgsPointV2& pt ) const
6981
{
7082
return ( pt.wkbType() == wkbType() &&
@@ -107,6 +119,12 @@ bool QgsPointV2::fromWkb( const unsigned char* wkb )
107119
return true;
108120
}
109121

122+
/***************************************************************************
123+
* This class is considered CRITICAL and any change MUST be accompanied with
124+
* full unit tests.
125+
* See details in QEP #17
126+
****************************************************************************/
127+
110128
bool QgsPointV2::fromWkt( const QString& wkt )
111129
{
112130
clear();
@@ -155,6 +173,12 @@ int QgsPointV2::wkbSize() const
155173
return size;
156174
}
157175

176+
/***************************************************************************
177+
* This class is considered CRITICAL and any change MUST be accompanied with
178+
* full unit tests.
179+
* See details in QEP #17
180+
****************************************************************************/
181+
158182
unsigned char* QgsPointV2::asWkb( int& binarySize ) const
159183
{
160184
binarySize = wkbSize();
@@ -199,7 +223,7 @@ QDomElement QgsPointV2::asGML2( QDomDocument& doc, int precision, const QString&
199223
QDomElement QgsPointV2::asGML3( QDomDocument& doc, int precision, const QString& ns ) const
200224
{
201225
QDomElement elemPoint = doc.createElementNS( ns, "Point" );
202-
QDomElement elemPosList = doc.createElementNS( ns, "posList" );
226+
QDomElement elemPosList = doc.createElementNS( ns, "pos" );
203227
elemPosList.setAttribute( "srsDimension", is3D() ? 3 : 2 );
204228
QString strCoordinates = qgsDoubleToString( mX, precision ) + ' ' + qgsDoubleToString( mY, precision );
205229
if ( is3D() )
@@ -210,6 +234,12 @@ QDomElement QgsPointV2::asGML3( QDomDocument& doc, int precision, const QString&
210234
return elemPoint;
211235
}
212236

237+
/***************************************************************************
238+
* This class is considered CRITICAL and any change MUST be accompanied with
239+
* full unit tests.
240+
* See details in QEP #17
241+
****************************************************************************/
242+
213243
QString QgsPointV2::asJSON( int precision ) const
214244
{
215245
return "{\"type\": \"Point\", \"coordinates\": ["
@@ -243,6 +273,12 @@ void QgsPointV2::coordinateSequence( QList< QList< QList< QgsPointV2 > > >& coor
243273
coord.append( featureCoord );
244274
}
245275

276+
/***************************************************************************
277+
* This class is considered CRITICAL and any change MUST be accompanied with
278+
* full unit tests.
279+
* See details in QEP #17
280+
****************************************************************************/
281+
246282
bool QgsPointV2::moveVertex( const QgsVertexId& position, const QgsPointV2& newPos )
247283
{
248284
Q_UNUSED( position );
@@ -290,6 +326,12 @@ bool QgsPointV2::nextVertex( QgsVertexId& id, QgsPointV2& vertex ) const
290326
}
291327
}
292328

329+
/***************************************************************************
330+
* This class is considered CRITICAL and any change MUST be accompanied with
331+
* full unit tests.
332+
* See details in QEP #17
333+
****************************************************************************/
334+
293335
bool QgsPointV2::addZValue( double zValue )
294336
{
295337
if ( QgsWKBTypes::hasZ( mWkbType ) )

src/core/geometry/qgspointv2.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020

2121
#include "qgsabstractgeometryv2.h"
2222

23+
/***************************************************************************
24+
* This class is considered CRITICAL and any change MUST be accompanied with
25+
* full unit tests in testqgsgeometry.cpp.
26+
* See details in QEP #17
27+
****************************************************************************/
28+
2329
/** \ingroup core
2430
* \class QgsPointV2
2531
* \brief Point geometry type, with support for z-dimension and m-values.

tests/src/core/testqgsgeometry.cpp

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,26 @@ void TestQgsGeometry::pointV2()
514514
QVERIFY( !p14.fromWkt( "Polygon()" ) );
515515
QCOMPARE( p14.wkbType(), QgsWKBTypes::Unknown );
516516

517-
//TODO asGML2, asGML3, asJSON
517+
//asGML2
518+
QgsPointV2 exportPoint( 1, 2 );
519+
QgsPointV2 exportPointFloat( 1 / 3.0, 2 / 3.0 );
520+
QDomDocument doc( "gml" );
521+
QString expectedGML2( "<Point xmlns=\"gml\"><coordinates xmlns=\"gml\">1,2</coordinates></Point>" );
522+
QCOMPARE( elemToString( exportPoint.asGML2( doc ) ), expectedGML2 );
523+
QString expectedGML2prec3( "<Point xmlns=\"gml\"><coordinates xmlns=\"gml\">0.333,0.667</coordinates></Point>" );
524+
QCOMPARE( elemToString( exportPointFloat.asGML2( doc, 3 ) ), expectedGML2prec3 );
525+
526+
//asGML3
527+
QString expectedGML3( "<Point xmlns=\"gml\"><pos xmlns=\"gml\" srsDimension=\"2\">1 2</pos></Point>" );
528+
QCOMPARE( elemToString( exportPoint.asGML3( doc ) ), expectedGML3 );
529+
QString expectedGML3prec3( "<Point xmlns=\"gml\"><pos xmlns=\"gml\" srsDimension=\"2\">0.333 0.667</pos></Point>" );
530+
QCOMPARE( elemToString( exportPointFloat.asGML3( doc, 3 ) ), expectedGML3prec3 );
531+
532+
//asJSON
533+
QString expectedJson( "{\"type\": \"Point\", \"coordinates\": [1, 2]}" );
534+
QCOMPARE( exportPoint.asJSON(), expectedJson );
535+
QString expectedJsonPrec3( "{\"type\": \"Point\", \"coordinates\": [0.333, 0.667]}" );
536+
QCOMPARE( exportPointFloat.asJSON( 3 ), expectedJsonPrec3 );
518537

519538
//bounding box
520539
QgsPointV2 p15( 1.0, 2.0 );
@@ -1060,7 +1079,7 @@ void TestQgsGeometry::exportToGeoJSON()
10601079
QString obtained = geom->exportToGeoJSON();
10611080
QString geojson = "{\"type\": \"Point\", \"coordinates\": [40, 50]}";
10621081
QCOMPARE( obtained, geojson );
1063-
1082+
10641083
//MultiPoint
10651084
wkt = "MultiPoint (0 0, 10 0, 10 10, 20 10)";
10661085
geom.reset( QgsGeometry::fromWkt( wkt ) );
@@ -1074,14 +1093,14 @@ void TestQgsGeometry::exportToGeoJSON()
10741093
obtained = geom->exportToGeoJSON();
10751094
geojson = "{\"type\": \"LineString\", \"coordinates\": [ [0, 0], [10, 0], [10, 10], [20, 10]]}";
10761095
QCOMPARE( obtained, geojson );
1077-
1096+
10781097
//MultiLineString
10791098
wkt = "MultiLineString ((0 0, 10 0, 10 10, 20 10),(30 30, 40 30, 40 40, 50 40))";
10801099
geom.reset( QgsGeometry::fromWkt( wkt ) );
10811100
obtained = geom->exportToGeoJSON();
10821101
geojson = "{\"type\": \"MultiLineString\", \"coordinates\": [[ [0, 0], [10, 0], [10, 10], [20, 10]], [ [30, 30], [40, 30], [40, 40], [50, 40]]] }";
10831102
QCOMPARE( obtained, geojson );
1084-
1103+
10851104
//Polygon
10861105
wkt = "Polygon ((0 0, 10 0, 10 10, 0 10, 0 0 ),(2 2, 4 2, 4 4, 2 4, 2 2))";
10871106
geom.reset( QgsGeometry::fromWkt( wkt ) );
@@ -1162,5 +1181,14 @@ void TestQgsGeometry::dumpPolyline( QgsPolyline &thePolyline )
11621181
mpPainter->drawPolyline( myPoints );
11631182
}
11641183

1184+
QString TestQgsGeometry::elemToString( const QDomElement& elem ) const
1185+
{
1186+
QString s;
1187+
QTextStream stream( &s );
1188+
elem.save( stream, -1 );
1189+
1190+
return s;
1191+
}
1192+
11651193
QTEST_MAIN( TestQgsGeometry )
11661194
#include "testqgsgeometry.moc"

0 commit comments

Comments
 (0)