void TestQgsDistanceArea::collections()
{
  //test measuring for collections
  QgsDistanceArea myDa;
  myDa.setSourceAuthId( "EPSG:4030" );
  myDa.setEllipsoidalMode( true );
  myDa.setEllipsoid( "WGS84" );

  //collection of lines, should be sum of line length
  QgsGeometry lines( QgsGeometryFactory::geomFromWkt( "GeometryCollection( LineString(0 36.53, 5.76 -48.16), LineString(0 25.54, 24.20 36.70) )" ) );
  double result = myDa.measureLength( &lines );
  QGSCOMPARENEAR( result, 12006159, 1 );
  result = myDa.measureArea( &lines );
  QVERIFY( qgsDoubleNear( result, 0 ) );

  //collection of polygons
  QgsGeometry polys( QgsGeometryFactory::geomFromWkt( "GeometryCollection( Polygon((0 36.53, 5.76 -48.16, 0 25.54, 0 36.53)), Polygon((10 20, 15 20, 15 10, 10 20)) )" ) );
  result = myDa.measureArea( &polys );
  QGSCOMPARENEAR( result, 670434859475LL, 1 );
  result = myDa.measureLength( &polys );
  QVERIFY( qgsDoubleNear( result, 0 ) );

  //mixed collection
  QgsGeometry mixed( QgsGeometryFactory::geomFromWkt( "GeometryCollection( LineString(0 36.53, 5.76 -48.16), LineString(0 25.54, 24.20 36.70), Polygon((0 36.53, 5.76 -48.16, 0 25.54, 0 36.53)), Polygon((10 20, 15 20, 15 10, 10 20)) )" ) );
  //measure area specifically
  result = myDa.measureArea( &mixed );
  QGSCOMPARENEAR( result, 670434859475LL, 1 );
  //measure length
  result = myDa.measureLength( &mixed );
  QGSCOMPARENEAR( result, 12006159, 1 );
}
void TestQgsDistanceArea::test_distances()
{
    // Read the file of Geod data
    // Column 0 (first) is latitude point 1
    // Column 1 is longitude point 1
    // Column 3 is latitude point 2
    // Column 4 is longitude point 3
    // Column 6 is the resulting distance in meters on the WGS84 ellipsoid
    // Note: lat is north/south, so the QgsPoint should be ( long, lat )
    // See http://geographiclib.sourceforge.net/html/geodesic.html#testgeod

    // Set up DA
    QgsDistanceArea myDa;
    myDa.setSourceAuthId( "EPSG:4030" );
    myDa.setEllipsoidalMode( true );
    myDa.setEllipsoid( "WGS84" );

    QString myFileName = QString( TEST_DATA_DIR ) + "/GeodTest-nano.dat";

    QFile myFile( myFileName );
    if ( ! myFile.open( QIODevice::ReadOnly | QIODevice::Text ) )
    {
        QFAIL( "Couldn't open file" );
        return;
    }
    QTextStream in( & myFile );
    while ( !in.atEnd() )
    {
        QString line = in.readLine();
        // Some test points (antipodal) does not converge with the chosen algorithm!
        // See calcaulator at http://www.movable-type.co.uk/scripts/latlong-vincenty.html
        // These are commented out.
        if ( line[0] != '#' )
        {
            QStringList myLineList = line.split( ' ' ); // Split fields on space.
            // Create points
            QgsPoint p1( myLineList[1].toDouble(), myLineList[0].toDouble() );
            QgsPoint p2( myLineList[4].toDouble(), myLineList[3].toDouble() );
            double result = myDa.measureLine( p1, p2 );
            // QgsDebugMsg( QString( "Distance from %1 to %2 is %3" ).arg( p1.toString( 15 ) ).arg( p2.toString( 15 ) ).arg( result, 0, 'g', 15 ) );
            // QgsDebugMsg( QString( "Distance should be %1" ).arg( myLineList[6] ) );
            // Check result is less than 0.5mm from expected.
            QVERIFY( qAbs( result -  myLineList[6].toDouble() ) < 0.0005 );
        }
    }

}