QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
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 <gdal_alg.h>
20#include "qgspoint.h"
21#include "qgis_analysis.h"
22#include "qgis_sip.h"
23
34{
35 Q_GADGET
36
37 public:
38
42 enum class TransformMethod : int
43 {
44 Linear,
45 Helmert,
46 PolynomialOrder1,
47 PolynomialOrder2,
48 PolynomialOrder3,
49 ThinPlateSpline,
50 Projective,
51 InvalidTransform = 65535
52 };
53 Q_ENUM( TransformMethod )
54
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
157
161 bool getOriginScale( QgsPointXY &origin, double &scaleX, double &scaleY ) const;
162
163 QgsGcpTransformerInterface *clone() const override;
164 bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) override;
165 int minimumGcpCount() const override;
166 GDALTransformerFunc GDALTransformer() const override;
167 void *GDALTransformerArgs() const override;
168 TransformMethod method() const override;
169
170 private:
171 struct LinearParameters
172 {
173 QgsPointXY origin;
174 double scaleX = 1;
175 double scaleY = 1;
176 bool invertYAxis = false;
177 } mParameters;
178
179 static int linearTransform( void *pTransformerArg, int bDstToSrc, int nPointCount,
180 double *x, double *y, double *z, int *panSuccess );
181
182};
183
191{
192 public:
193
196
200 bool getOriginScaleRotation( QgsPointXY &origin, double &scale, double &rotation ) const;
201
202 QgsGcpTransformerInterface *clone() const override;
203 bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) override;
204 int minimumGcpCount() const override;
205 GDALTransformerFunc GDALTransformer() const override;
206 void *GDALTransformerArgs() const override;
207 TransformMethod method() const override;
208
209 private:
210
211 struct HelmertParameters
212 {
213 QgsPointXY origin;
214 double scale;
215 double angle;
216 bool invertYAxis = false;
217 };
218 HelmertParameters mHelmertParameters;
219
220 static int helmertTransform( void *pTransformerArg, int bDstToSrc, int nPointCount,
221 double *x, double *y, double *z, int *panSuccess );
222
223};
224
232{
233 public:
234
236 QgsGDALGeorefTransform( bool useTPS, unsigned int polynomialOrder );
237 ~QgsGDALGeorefTransform() override;
238
239 QgsGcpTransformerInterface *clone() const override;
240 bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) override;
241 int minimumGcpCount() const override;
242 GDALTransformerFunc GDALTransformer() const override;
243 void *GDALTransformerArgs() const override;
244 TransformMethod method() const override;
245
246 private:
247 void destroyGdalArgs();
248
249 QVector<QgsPointXY> mSourceCoords;
250 QVector<QgsPointXY> mDestCoordinates;
251 bool mInvertYAxis = false;
252
253 const int mPolynomialOrder;
254 const bool mIsTPSTransform;
255
256 void *mGDALTransformerArgs = nullptr;
257
258};
259
270{
271 public:
272
275
276 QgsGcpTransformerInterface *clone() const override;
277 bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) override;
278 int minimumGcpCount() const override;
279 GDALTransformerFunc GDALTransformer() const override;
280 void *GDALTransformerArgs() const override;
281 TransformMethod method() const override;
282
283 private:
284 struct ProjectiveParameters
285 {
286 double H[9]; // Homography
287 double Hinv[9]; // Inverted homography
288 bool hasInverse; // Could the inverted homography be calculated?
289 } mParameters;
290
291 static int projectiveTransform( void *pTransformerArg, int bDstToSrc, int nPointCount,
292 double *x, double *y, double *z, int *panSuccess );
293
294};
295
296#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
Constructor for QgsHelmertGeorefTransform.
A simple transform which is parametrized by a translation and anistotropic scale.
QgsLinearGeorefTransform()=default
Constructor for QgsLinearGeorefTransform.
Custom exception class which is raised when an operation is not supported.
Definition: qgsexception.h:118
A class to represent a 2D point.
Definition: qgspointxy.h:59
A planar projective transform, expressed by a homography.
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
Definition: MathUtils.cpp:786
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_ABSTRACT
Definition: qgis_sip.h:208
#define SIP_FACTORY
Definition: qgis_sip.h:76
#define SIP_INOUT
Definition: qgis_sip.h:71
#define SIP_THROW(name,...)
Definition: qgis_sip.h:198