1 /***************************************************************************
2                              qgsgcpgeometrytransformer.cpp
3                              ----------------------
4     begin                : February 2021
5     copyright            : (C) 2021 by Nyall Dawson
6     email                : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17 
18 #include "qgsgcpgeometrytransformer.h"
19 #include "qgsgeometry.h"
20 
QgsGcpGeometryTransformer(QgsGcpTransformerInterface * gcpTransformer)21 QgsGcpGeometryTransformer::QgsGcpGeometryTransformer( QgsGcpTransformerInterface *gcpTransformer )
22   : mGcpTransformer( gcpTransformer )
23 {
24 
25 }
26 
QgsGcpGeometryTransformer(QgsGcpTransformerInterface::TransformMethod method,const QVector<QgsPointXY> & sourceCoordinates,const QVector<QgsPointXY> & destinationCoordinates)27 QgsGcpGeometryTransformer::QgsGcpGeometryTransformer( QgsGcpTransformerInterface::TransformMethod method, const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates )
28   : mGcpTransformer( QgsGcpTransformerInterface::createFromParameters( method, sourceCoordinates, destinationCoordinates ) )
29 {
30 
31 }
32 
33 QgsGcpGeometryTransformer::~QgsGcpGeometryTransformer() = default;
34 
transformPoint(double & x,double & y,double &,double &)35 bool QgsGcpGeometryTransformer::transformPoint( double &x, double &y, double &, double & )
36 {
37   if ( !mGcpTransformer )
38     return false;
39 
40   return mGcpTransformer->transform( x, y );
41 }
42 
transform(const QgsGeometry & geometry,bool & ok,QgsFeedback * feedback)43 QgsGeometry QgsGcpGeometryTransformer::transform( const QgsGeometry &geometry, bool &ok, QgsFeedback *feedback )
44 {
45   ok = false;
46   if ( geometry.isNull() )
47   {
48     ok = true;
49     return QgsGeometry();
50   }
51 
52   std::unique_ptr< QgsAbstractGeometry > res( geometry.constGet()->clone() );
53 
54   ok = res->transform( this, feedback );
55 
56   return QgsGeometry( std::move( res ) );
57 }
58 
gcpTransformer() const59 QgsGcpTransformerInterface *QgsGcpGeometryTransformer::gcpTransformer() const
60 {
61   return mGcpTransformer.get();
62 }
63 
setGcpTransformer(QgsGcpTransformerInterface * gcpTransformer)64 void QgsGcpGeometryTransformer::setGcpTransformer( QgsGcpTransformerInterface *gcpTransformer )
65 {
66   mGcpTransformer.reset( gcpTransformer );
67 }
68