Skip to content

Commit 143300d

Browse files
committed
Added test of distance calculations and test data
1 parent 182a64e commit 143300d

File tree

3 files changed

+166
-5
lines changed

3 files changed

+166
-5
lines changed

tests/src/core/testqgsdistancearea.cpp

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
* *
1414
***************************************************************************/
1515
#include <QtTest>
16+
#include <QFile>
17+
#include <QTextStream>
1618
#include <QObject>
1719
#include <QString>
18-
#include <QObject>
20+
#include <QStringList>
1921
#include <qgsapplication.h>
2022
//header for class being tested
2123
#include <qgsdistancearea.h>
@@ -48,7 +50,7 @@ void TestQgsDistanceArea::basic()
4850
{
4951
QgsPoint p1( 1.0, 3.0 ), p2(-2.0, -1.0 );
5052
QgsDistanceArea daA;
51-
double resultA, resultB;
53+
double resultA, resultB, resultC;
5254

5355
daA.setEllipsoid( "NONE" );
5456
resultA = daA.measureLine( p1, p2 );
@@ -72,14 +74,60 @@ void TestQgsDistanceArea::basic()
7274
QVERIFY( ! qFuzzyCompare( resultA, resultB ) );
7375

7476
// Test assignment
75-
daA = daB;
76-
resultA = daA.measureLine( p1, p2 );
77-
QCOMPARE( resultA, resultB );
77+
QgsDistanceArea * daC;
78+
daC = new QgsDistanceArea;
79+
*daC = daB;
80+
resultC = daC->measureLine( p1, p2 );
81+
QCOMPARE( resultB, resultC );
82+
delete daC;
7883

7984
};
8085

8186
void TestQgsDistanceArea::test_distances()
8287
{
88+
// Read the file of Geod data
89+
// Column 0 (first) is latitude point 1
90+
// Column 1 is longitude point 1
91+
// Column 3 is latitude point 2
92+
// Column 4 is longitude point 3
93+
// Column 6 is the resulting distance in meters on the WGS84 ellipsoid
94+
// Note: lat is north/south, so the QgsPoint should be ( long, lat )
95+
// See http://geographiclib.sourceforge.net/html/geodesic.html#testgeod
96+
97+
// Set up DA
98+
QgsDistanceArea myDa;
99+
myDa.setSourceAuthId( "EPSG:4030" );
100+
myDa.setEllipsoidalMode ( true );
101+
myDa.setEllipsoid( "WGS84" );
102+
103+
QString myFileName = QString( TEST_DATA_DIR ) + QDir::separator() + "GeodTest-nano.dat";
104+
105+
QFile myFile( myFileName );
106+
if ( ! myFile.open( QIODevice::ReadOnly | QIODevice::Text))
107+
{
108+
QFAIL( "Couldn't open file" );
109+
return;
110+
}
111+
QTextStream in( & myFile );
112+
while (!in.atEnd()) {
113+
QString line = in.readLine();
114+
// Some test points (antipodal) does not converge with the chosen algorithm!
115+
// See calcaulator at http://www.movable-type.co.uk/scripts/latlong-vincenty.html
116+
// These are commented out.
117+
if (line[0] != '#' )
118+
{
119+
QStringList myLineList = line.split(' '); // Split fields on space.
120+
// Create points
121+
QgsPoint p1( myLineList[1].toDouble(), myLineList[0].toDouble() );
122+
QgsPoint p2( myLineList[4].toDouble(), myLineList[3].toDouble() );
123+
double result = myDa.measureLine( p1, p2 );
124+
// QgsDebugMsg( QString( "Distance from %1 to %2 is %3" ).arg( p1.toString( 15 ) ).arg( p2.toString( 15 ) ).arg( result, 0, 'g', 15 ) );
125+
// QgsDebugMsg( QString( "Distance should be %1" ).arg( myLineList[6] ) );
126+
// Check result is less than 0.5mm from expected.
127+
QVERIFY ( qAbs( result - myLineList[6].toDouble() ) < 0.0005 );
128+
}
129+
}
130+
83131
};
84132

85133
void TestQgsDistanceArea::unit_conversions()

0 commit comments

Comments
 (0)