Skip to content

Commit 57677f6

Browse files
committed
Add test for QgsCoordinateTransform::conversionFactor
1 parent 89526a0 commit 57677f6

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tests/src/core/testqgscoordinatetransform.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class TestQgsCoordinateTransform: public QObject
3636
void isValid();
3737
void isShortCircuited();
3838
void contextShared();
39+
void conversionFactor();
40+
void conversionFactor_data();
3941

4042
private:
4143

@@ -213,6 +215,42 @@ void TestQgsCoordinateTransform::contextShared()
213215
QCOMPARE( copy2.sourceDestinationDatumTransforms(), expected );
214216
}
215217

218+
void TestQgsCoordinateTransform::conversionFactor()
219+
{
220+
QFETCH( QgsCoordinateReferenceSystem, sourceCrs );
221+
QFETCH( QgsCoordinateReferenceSystem, destCrs );
222+
QFETCH( QgsRectangle, rect );
223+
QFETCH( double, factor );
224+
225+
QgsCoordinateTransform ct( sourceCrs, destCrs, QgsProject::instance() );
226+
227+
// qDebug() << QString::number(ct.conversionFactor( rect ), 'g', 17) ;
228+
QVERIFY( qgsDoubleNear( ct.conversionFactor( rect ), factor ) );
229+
}
230+
231+
void TestQgsCoordinateTransform::conversionFactor_data()
232+
{
233+
QTest::addColumn<QgsCoordinateReferenceSystem>( "sourceCrs" );
234+
QTest::addColumn<QgsCoordinateReferenceSystem>( "destCrs" );
235+
QTest::addColumn<QgsRectangle>( "rect" );
236+
QTest::addColumn<double>( "factor" );
237+
238+
QTest::newRow( "Different map units" )
239+
<< QgsCoordinateReferenceSystem::fromEpsgId( 2056 )
240+
<< QgsCoordinateReferenceSystem::fromEpsgId( 4326 )
241+
<< QgsRectangle( 2550000, 1200000, 2550100, 1200100 )
242+
<< 1.1223316038381985e-5;
243+
QTest::newRow( "Same map units" )
244+
<< QgsCoordinateReferenceSystem::fromEpsgId( 2056 )
245+
<< QgsCoordinateReferenceSystem::fromEpsgId( 21781 )
246+
<< QgsRectangle( 2550000, 1200000, 2550100, 1200100 )
247+
<< 1.0000000000248837;
248+
QTest::newRow( "Same CRS" )
249+
<< QgsCoordinateReferenceSystem::fromEpsgId( 2056 )
250+
<< QgsCoordinateReferenceSystem::fromEpsgId( 2056 )
251+
<< QgsRectangle( 2550000, 1200000, 2550100, 1200100 )
252+
<< 1.0;
253+
}
216254

217255
void TestQgsCoordinateTransform::transformBoundingBox()
218256
{

0 commit comments

Comments
 (0)