QGIS API Documentation 3.41.0-Master (af5edcb665c)
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:
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
56
57 virtual ~QgsGcpTransformerInterface() = default;
58
61
63 QgsGcpTransformerInterface &operator=( const QgsGcpTransformerInterface &other ) = delete;
64
71 virtual QgsGcpTransformerInterface *clone() const = 0 SIP_FACTORY;
72
81 virtual bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) SIP_THROW( QgsNotSupportedException ) = 0;
82
86 virtual int minimumGcpCount() const = 0;
87
91 virtual TransformMethod method() const = 0;
92
100 bool transform( double &x SIP_INOUT, double &y SIP_INOUT, bool inverseTransform = false ) const;
101
105 static QString methodToString( TransformMethod method );
106
113
122 static QgsGcpTransformerInterface *createFromParameters( TransformMethod method, const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates ) SIP_THROW( QgsNotSupportedException ) SIP_FACTORY;
123
124#ifndef SIP_RUN
125
129 virtual GDALTransformerFunc GDALTransformer() const = 0;
130
134 virtual void *GDALTransformerArgs() const = 0;
135#endif
136
137 private:
138#ifdef SIP_RUN
140#endif
141};
142
150{
151 public:
153
157 bool getOriginScale( QgsPointXY &origin, double &scaleX, double &scaleY ) const;
158
159 QgsGcpTransformerInterface *clone() const override;
160 bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) override;
161 int minimumGcpCount() const override;
162 GDALTransformerFunc GDALTransformer() const override;
163 void *GDALTransformerArgs() const override;
164 TransformMethod method() const override;
165
166 private:
167 struct LinearParameters
168 {
169 QgsPointXY origin;
170 double scaleX = 1;
171 double scaleY = 1;
172 bool invertYAxis = false;
173 } mParameters;
174
175 static int linearTransform( void *pTransformerArg, int bDstToSrc, int nPointCount, double *x, double *y, double *z, int *panSuccess );
176};
177
185{
186 public:
188
192 bool getOriginScaleRotation( QgsPointXY &origin, double &scale, double &rotation ) const;
193
194 QgsGcpTransformerInterface *clone() const override;
195 bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) override;
196 int minimumGcpCount() const override;
197 GDALTransformerFunc GDALTransformer() const override;
198 void *GDALTransformerArgs() const override;
199 TransformMethod method() const override;
200
201 private:
202 struct HelmertParameters
203 {
204 QgsPointXY origin;
205 double scale = 0;
206 double angle = 0;
207 bool invertYAxis = false;
208 };
209 HelmertParameters mHelmertParameters;
210
211 static int helmertTransform( void *pTransformerArg, int bDstToSrc, int nPointCount, double *x, double *y, double *z, int *panSuccess );
212};
213
221{
222 public:
224 QgsGDALGeorefTransform( bool useTPS, unsigned int polynomialOrder );
225 ~QgsGDALGeorefTransform() override;
226
227 QgsGcpTransformerInterface *clone() const override;
228 bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) override;
229 int minimumGcpCount() const override;
230 GDALTransformerFunc GDALTransformer() const override;
231 void *GDALTransformerArgs() const override;
232 TransformMethod method() const override;
233
234 private:
235 void destroyGdalArgs();
236
237 QVector<QgsPointXY> mSourceCoords;
238 QVector<QgsPointXY> mDestCoordinates;
239 bool mInvertYAxis = false;
240
241 const int mPolynomialOrder;
242 const bool mIsTPSTransform;
243
244 void *mGDALTransformerArgs = nullptr;
245};
246
257{
258 public:
260
261 QgsGcpTransformerInterface *clone() const override;
262 bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) override;
263 int minimumGcpCount() const override;
264 GDALTransformerFunc GDALTransformer() const override;
265 void *GDALTransformerArgs() const override;
266 TransformMethod method() const override;
267
268 private:
269 struct ProjectiveParameters
270 {
271 double H[9]; // Homography
272 double Hinv[9]; // Inverted homography
273 bool hasInverse; // Could the inverted homography be calculated?
274 } mParameters;
275
276 static int projectiveTransform( void *pTransformerArg, int bDstToSrc, int nPointCount, double *x, double *y, double *z, int *panSuccess );
277};
278
279#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