Skip to content

Commit

Permalink
Add test for createGCPVectors
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Feb 9, 2022
1 parent f54fc59 commit 6255e7a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/app/georeferencer/qgsgcplist.cpp
Expand Up @@ -21,7 +21,7 @@

#include "qgsgcplist.h"

void QgsGCPList::createGCPVectors( QVector<QgsPointXY> &sourcePoints, QVector<QgsPointXY> &destinationPoints, const QgsCoordinateReferenceSystem &targetCrs ) const
void QgsGCPList::createGCPVectors( QVector<QgsPointXY> &sourcePoints, QVector<QgsPointXY> &destinationPoints, const QgsCoordinateReferenceSystem &targetCrs, const QgsCoordinateTransformContext &context ) const
{
const int targetSize = countEnabledPoints();
sourcePoints.clear();
Expand All @@ -37,7 +37,7 @@ void QgsGCPList::createGCPVectors( QVector<QgsPointXY> &sourcePoints, QVector<Qg
sourcePoints.push_back( pt->sourcePoint() );
if ( targetCrs.isValid() )
{
destinationPoints.push_back( pt->transformedDestinationPoint( targetCrs, QgsProject::instance()->transformContext() ) );
destinationPoints.push_back( pt->transformedDestinationPoint( targetCrs, context ) );
}
else
{
Expand Down
4 changes: 3 additions & 1 deletion src/app/georeferencer/qgsgcplist.h
Expand Up @@ -24,6 +24,7 @@ class QgsGeorefDataPoint;
class QgsGcpPoint;
class QgsPointXY;
class QgsCoordinateReferenceSystem;
class QgsCoordinateTransformContext;

/**
* A container for GCP data points.
Expand All @@ -41,7 +42,8 @@ class APP_EXPORT QgsGCPList : public QList<QgsGeorefDataPoint * >
* Creates vectors of source and destination points, where the destination points are all transformed to the
* specified \a targetCrs.
*/
void createGCPVectors( QVector<QgsPointXY> &sourcePoints, QVector<QgsPointXY> &destinationPoints, const QgsCoordinateReferenceSystem &targetCrs ) const;
void createGCPVectors( QVector<QgsPointXY> &sourcePoints, QVector<QgsPointXY> &destinationPoints,
const QgsCoordinateReferenceSystem &targetCrs, const QgsCoordinateTransformContext &context ) const;

/**
* Returns the count of currently enabled data points.
Expand Down
2 changes: 1 addition & 1 deletion src/app/georeferencer/qgsgcplistmodel.cpp
Expand Up @@ -87,7 +87,7 @@ void QgsGCPListModel::updateModel()
QVector<QgsPointXY> destinationCoordinates;

const QgsCoordinateReferenceSystem targetCrs( s.value( QStringLiteral( "/Plugin-GeoReferencer/targetsrs" ) ).toString() );
mGCPList->createGCPVectors( sourceCoordinates, destinationCoordinates, targetCrs );
mGCPList->createGCPVectors( sourceCoordinates, destinationCoordinates, targetCrs, QgsProject::instance()->transformContext() );

if ( mGeorefTransform )
{
Expand Down
2 changes: 1 addition & 1 deletion src/app/georeferencer/qgsgeorefmainwindow.cpp
Expand Up @@ -2030,7 +2030,7 @@ bool QgsGeoreferencerMainWindow::updateGeorefTransform()
QVector<QgsPointXY> sourceCoordinates;
QVector<QgsPointXY> destinationCoords;
if ( mGCPListWidget->gcpList() )
mGCPListWidget->gcpList()->createGCPVectors( sourceCoordinates, destinationCoords, mProjection );
mGCPListWidget->gcpList()->createGCPVectors( sourceCoordinates, destinationCoords, mProjection, QgsProject::instance()->transformContext() );
else
return false;

Expand Down
30 changes: 30 additions & 0 deletions tests/src/app/testqgsgeoreferencer.cpp
Expand Up @@ -187,7 +187,37 @@ void TestQgsGeoreferencer::testGcpList()
QgsGcpPoint( QgsPointXY( 111, 222 ), QgsPointXY( 333, 444 ), QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:28356" ) ), true )
} ) );


qDeleteAll( list );
list.clear();

// create gcp vectors
list.append( new QgsGeorefDataPoint( &c1, &c2,
QgsPointXY( 111, 222 ), QgsPointXY( -30, 40 ), QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:4326" ) ),
true ) );
list.append( new QgsGeorefDataPoint( &c1, &c2,
QgsPointXY( 11, 22 ), QgsPointXY( 16697923, -3503549 ), QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:3857" ) ),
true ) );
// disabled!
list.append( new QgsGeorefDataPoint( &c1, &c2,
QgsPointXY( 33, 44 ), QgsPointXY( 100, 200 ), QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:3857" ) ),
false ) );

QVector< QgsPointXY > sourcePoints;
QVector< QgsPointXY > destinationPoints;
list.createGCPVectors( sourcePoints, destinationPoints, QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:3857" ) ), QgsProject::instance()->transformContext() );
QCOMPARE( sourcePoints.size(), 2 );
QCOMPARE( sourcePoints.at( 0 ).x(), 111 );
QCOMPARE( sourcePoints.at( 0 ).y(), 222 );
QCOMPARE( sourcePoints.at( 1 ).x(), 11 );
QCOMPARE( sourcePoints.at( 1 ).y(), 22 );

QCOMPARE( destinationPoints.size(), 2 );
QGSCOMPARENEAR( destinationPoints.at( 0 ).x(), -3339584, 10000 );
QGSCOMPARENEAR( destinationPoints.at( 0 ).y(), 4865942, 10000 );
QCOMPARE( destinationPoints.at( 1 ).x(), 16697923 );
QCOMPARE( destinationPoints.at( 1 ).y(), -3503549 );

}

void TestQgsGeoreferencer::testTransformImageNoGeoference()
Expand Down

0 comments on commit 6255e7a

Please sign in to comment.