QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
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
56
58
59 virtual ~QgsGcpTransformerInterface() = default;
60
63
65 QgsGcpTransformerInterface &operator=( const QgsGcpTransformerInterface &other ) = delete;
66
73 virtual QgsGcpTransformerInterface *clone() const = 0 SIP_FACTORY;
74
83 virtual bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) SIP_THROW( QgsNotSupportedException ) = 0;
84
88 virtual int minimumGcpCount() const = 0;
89
93 virtual TransformMethod method() const = 0;
94
102 bool transform( double &x SIP_INOUT, double &y SIP_INOUT, bool inverseTransform = false ) const;
103
107 static QString methodToString( TransformMethod method );
108
115
124 static QgsGcpTransformerInterface *createFromParameters( TransformMethod method, const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates ) SIP_THROW( QgsNotSupportedException ) SIP_FACTORY;
125
126#ifndef SIP_RUN
127
131 virtual GDALTransformerFunc GDALTransformer() const = 0;
132
136 virtual void *GDALTransformerArgs() const = 0;
137#endif
138
139 private:
140
141#ifdef SIP_RUN
143#endif
144};
145
153{
154 public:
155
158
162 bool getOriginScale( QgsPointXY &origin, double &scaleX, double &scaleY ) const;
163
164 QgsGcpTransformerInterface *clone() const override;
165 bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) override;
166 int minimumGcpCount() const override;
167 GDALTransformerFunc GDALTransformer() const override;
168 void *GDALTransformerArgs() const override;
169 TransformMethod method() const override;
170
171 private:
172 struct LinearParameters
173 {
174 QgsPointXY origin;
175 double scaleX = 1;
176 double scaleY = 1;
177 bool invertYAxis = false;
178 } mParameters;
179
180 static int linearTransform( void *pTransformerArg, int bDstToSrc, int nPointCount,
181 double *x, double *y, double *z, int *panSuccess );
182
183};
184
192{
193 public:
194
197
201 bool getOriginScaleRotation( QgsPointXY &origin, double &scale, double &rotation ) const;
202
203 QgsGcpTransformerInterface *clone() const override;
204 bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) override;
205 int minimumGcpCount() const override;
206 GDALTransformerFunc GDALTransformer() const override;
207 void *GDALTransformerArgs() const override;
208 TransformMethod method() const override;
209
210 private:
211
212 struct HelmertParameters
213 {
214 QgsPointXY origin;
215 double scale = 0;
216 double angle = 0;
217 bool invertYAxis = false;
218 };
219 HelmertParameters mHelmertParameters;
220
221 static int helmertTransform( void *pTransformerArg, int bDstToSrc, int nPointCount,
222 double *x, double *y, double *z, int *panSuccess );
223
224};
225
233{
234 public:
235
237 QgsGDALGeorefTransform( bool useTPS, unsigned int polynomialOrder );
238 ~QgsGDALGeorefTransform() override;
239
240 QgsGcpTransformerInterface *clone() const override;
241 bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) override;
242 int minimumGcpCount() const override;
243 GDALTransformerFunc GDALTransformer() const override;
244 void *GDALTransformerArgs() const override;
245 TransformMethod method() const override;
246
247 private:
248 void destroyGdalArgs();
249
250 QVector<QgsPointXY> mSourceCoords;
251 QVector<QgsPointXY> mDestCoordinates;
252 bool mInvertYAxis = false;
253
254 const int mPolynomialOrder;
255 const bool mIsTPSTransform;
256
257 void *mGDALTransformerArgs = nullptr;
258
259};
260
271{
272 public:
273
276
277 QgsGcpTransformerInterface *clone() const override;
278 bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) override;
279 int minimumGcpCount() const override;
280 GDALTransformerFunc GDALTransformer() const override;
281 void *GDALTransformerArgs() const override;
282 TransformMethod method() const override;
283
284 private:
285 struct ProjectiveParameters
286 {
287 double H[9]; // Homography
288 double Hinv[9]; // Inverted homography
289 bool hasInverse; // Could the inverted homography be calculated?
290 } mParameters;
291
292 static int projectiveTransform( void *pTransformerArg, int bDstToSrc, int nPointCount,
293 double *x, double *y, double *z, int *panSuccess );
294
295};
296
297#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.
A class to represent a 2D point.
Definition qgspointxy.h:59
A planar projective transform, expressed by a homography.
#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