Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Feb 21, 2021
1 parent d8a6d36 commit 77b8982
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/analysis/georeferencing/qgsgcpgeometrytransformer.cpp
Expand Up @@ -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() );

Expand Down
36 changes: 36 additions & 0 deletions tests/src/analysis/testqgsgcptransformer.cpp
Expand Up @@ -19,6 +19,8 @@
#include "qgsapplication.h"
#include "qgscoordinatereferencesystem.h"
#include "qgsrectangle.h"
#include "qgsgcpgeometrytransformer.h"
#include "qgsgeometry.h"

#include <QDir>

Expand Down Expand Up @@ -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 )
Expand Down

0 comments on commit 77b8982

Please sign in to comment.