Skip to content
Permalink
Browse files

Add test

  • Loading branch information
nyalldawson committed Feb 21, 2021
1 parent d8a6d36 commit 77b898230c596ed1292dbbba07edb439e4489b71
@@ -42,8 +42,12 @@ bool QgsGcpGeometryTransformer::transformPoint( double &x, double &y, double &,

QgsGeometry QgsGcpGeometryTransformer::transform( const QgsGeometry &geometry, bool &ok, QgsFeedback *feedback )
{
ok = false;
if ( geometry.isNull() )
{
ok = true;
return QgsGeometry();
}

std::unique_ptr< QgsAbstractGeometry > res( geometry.constGet()->clone() );

@@ -19,6 +19,8 @@
#include "qgsapplication.h"
#include "qgscoordinatereferencesystem.h"
#include "qgsrectangle.h"
#include "qgsgcpgeometrytransformer.h"
#include "qgsgeometry.h"

#include <QDir>

@@ -1524,6 +1526,40 @@ class TestQgsGcpTransformer : public QObject
QGSCOMPARENEAR( y, 186514, 1 );
}


// geometry transformer
void testGeometryTransfomer()
{
QgsGcpGeometryTransformer transformer( QgsGcpTransformerInterface::TransformMethod::Projective,
QVector< QgsPointXY >() << QgsPointXY( 288, 1126 )
<< QgsPointXY( 2352, 716 )
<< QgsPointXY( 2067, 2398 )
<< QgsPointXY( 1102, 2209 ),
QVector< QgsPointXY >() << QgsPointXY( 321210, 130280 )
<< QgsPointXY( 322698, 129979 )
<< QgsPointXY( 322501, 192061 )
<< QgsPointXY( 321803, 192198 ) );

QgsGeometry geom = QgsGeometry::fromWkt( QStringLiteral( "LineString(288 1000, 2352 1150, 2067 2500, 1102 2300)" ) );
bool ok = false;
QCOMPARE( transformer.transform( geom, ok ).asWkt( 0 ), QStringLiteral( "LineString (321256 123764, 322688 142909, 322495 197069, 321782 198051)" ) );
QVERIFY( ok );

// invalid parameters -- not enough GCPs
QgsGcpGeometryTransformer transformer2( QgsGcpTransformerInterface::TransformMethod::PolynomialOrder2,
QVector< QgsPointXY >() << QgsPointXY( 288, 1126 )
<< QgsPointXY( 2352, 716 )
<< QgsPointXY( 2067, 2398 )
<< QgsPointXY( 1102, 2209 ),
QVector< QgsPointXY >() << QgsPointXY( 321210, 130280 )
<< QgsPointXY( 322698, 129979 )
<< QgsPointXY( 322501, 192061 )
<< QgsPointXY( 321803, 192198 ) );
QCOMPARE( transformer2.transform( geom, ok ).asWkt( 0 ), QStringLiteral( "LineString (288 1000, 2352 1150, 2067 2500, 1102 2300)" ) );
QVERIFY( !ok );
}


};

QGSTEST_MAIN( TestQgsGcpTransformer )

0 comments on commit 77b8982

Please sign in to comment.