QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
qgsgcptransformer.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsgcptransformer.h
3 --------------------------------------
4 Date : 18-Feb-2009
5 Copyright : (c) 2009 by Manuel Massing
6 Email : m.massing at warped-space.de
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSGCPTRANSFORMER_H
17#define QGSGCPTRANSFORMER_H
18
19#include <QObject>
20#include <gdal_alg.h>
21#include "qgis_analysis.h"
22#include "qgis_sip.h"
23#include "qgspointxy.h"
24
35{
36 Q_GADGET
37
38 public:
39
43 enum class TransformMethod : int
44 {
45 Linear,
46 Helmert,
47 PolynomialOrder1,
48 PolynomialOrder2,
49 PolynomialOrder3,
50 ThinPlateSpline,
51 Projective,
52 InvalidTransform = 65535
53 };
54 Q_ENUM( TransformMethod )
55
57
58 virtual ~QgsGcpTransformerInterface() = default;
59
62
64 QgsGcpTransformerInterface &operator=( const QgsGcpTransformerInterface &other ) = delete;
65
72 virtual QgsGcpTransformerInterface *clone() const = 0 SIP_FACTORY;
73
82 virtual bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) SIP_THROW( QgsNotSupportedException ) = 0;
83
87 virtual int minimumGcpCount() const = 0;
88
92 virtual TransformMethod method() const = 0;
93
101 bool transform( double &x SIP_INOUT, double &y SIP_INOUT, bool inverseTransform = false ) const;
102
106 static QString methodToString( TransformMethod method );
107
114
123 static QgsGcpTransformerInterface *createFromParameters( TransformMethod method, const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates ) SIP_THROW( QgsNotSupportedException ) SIP_FACTORY;
124
125#ifndef SIP_RUN
126
130 virtual GDALTransformerFunc GDALTransformer() const = 0;
131
135 virtual void *GDALTransformerArgs() const = 0;
136#endif
137
138 private:
139
140#ifdef SIP_RUN
142#endif
143};
144
152{
153 public:
154
156
160 bool getOriginScale( QgsPointXY &origin, double &scaleX, double &scaleY ) const;
161
162 QgsGcpTransformerInterface *clone() const override;
163 bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) override;
164 int minimumGcpCount() const override;
165 GDALTransformerFunc GDALTransformer() const override;
166 void *GDALTransformerArgs() const override;
167 TransformMethod method() const override;
168
169 private:
170 struct LinearParameters
171 {
172 QgsPointXY origin;
173 double scaleX = 1;
174 double scaleY = 1;
175 bool invertYAxis = false;
176 } mParameters;
177
178 static int linearTransform( void *pTransformerArg, int bDstToSrc, int nPointCount,
179 double *x, double *y, double *z, int *panSuccess );
180
181};
182
190{
191 public:
192
194
198 bool getOriginScaleRotation( QgsPointXY &origin, double &scale, double &rotation ) const;
199
200 QgsGcpTransformerInterface *clone() const override;
201 bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) override;
202 int minimumGcpCount() const override;
203 GDALTransformerFunc GDALTransformer() const override;
204 void *GDALTransformerArgs() const override;
205 TransformMethod method() const override;
206
207 private:
208
209 struct HelmertParameters
210 {
211 QgsPointXY origin;
212 double scale = 0;
213 double angle = 0;
214 bool invertYAxis = false;
215 };
216 HelmertParameters mHelmertParameters;
217
218 static int helmertTransform( void *pTransformerArg, int bDstToSrc, int nPointCount,
219 double *x, double *y, double *z, int *panSuccess );
220
221};
222
230{
231 public:
232
234 QgsGDALGeorefTransform( bool useTPS, unsigned int polynomialOrder );
235 ~QgsGDALGeorefTransform() override;
236
237 QgsGcpTransformerInterface *clone() const override;
238 bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) override;
239 int minimumGcpCount() const override;
240 GDALTransformerFunc GDALTransformer() const override;
241 void *GDALTransformerArgs() const override;
242 TransformMethod method() const override;
243
244 private:
245 void destroyGdalArgs();
246
247 QVector<QgsPointXY> mSourceCoords;
248 QVector<QgsPointXY> mDestCoordinates;
249 bool mInvertYAxis = false;
250
251 const int mPolynomialOrder;
252 const bool mIsTPSTransform;
253
254 void *mGDALTransformerArgs = nullptr;
255
256};
257
268{
269 public:
270
272
273 QgsGcpTransformerInterface *clone() const override;
274 bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) override;
275 int minimumGcpCount() const override;
276 GDALTransformerFunc GDALTransformer() const override;
277 void *GDALTransformerArgs() const override;
278 TransformMethod method() const override;
279
280 private:
281 struct ProjectiveParameters
282 {
283 double H[9]; // Homography
284 double Hinv[9]; // Inverted homography
285 bool hasInverse; // Could the inverted homography be calculated?
286 } mParameters;
287
288 static int projectiveTransform( void *pTransformerArg, int bDstToSrc, int nPointCount,
289 double *x, double *y, double *z, int *panSuccess );
290
291};
292
293#endif //QGSGCPTRANSFORMER_H
Interface to gdal thin plate splines and 1st/2nd/3rd order polynomials.
An interface for Ground Control Points (GCP) based transformations.
TransformMethod
Available transformation methods.
virtual void * GDALTransformerArgs() const =0
Returns pointer to the GDALTransformer arguments.
virtual GDALTransformerFunc GDALTransformer() const =0
Returns function pointer to the GDALTransformer function.
2-dimensional helmert transform, parametrised by isotropic scale, rotation angle and translation.
QgsHelmertGeorefTransform()=default
A simple transform which is parametrized by a translation and anistotropic scale.
QgsLinearGeorefTransform()=default
Custom exception class which is raised when an operation is not supported.
A class to represent a 2D point.
Definition qgspointxy.h:60
A planar projective transform, expressed by a homography.
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_ABSTRACT
Definition qgis_sip.h:213
#define SIP_FACTORY
Definition qgis_sip.h:76
#define SIP_INOUT
Definition qgis_sip.h:71
#define SIP_THROW(name,...)
Definition qgis_sip.h:203