QGIS API Documentation 3.99.0-Master (26c88405ac0)
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 <gdal_alg.h>
20
21#include "qgis_analysis.h"
22#include "qgis_sip.h"
23#include "qgspointxy.h"
24
25#include <QObject>
26
37{
38 Q_GADGET
39
40 public:
41
45 enum class TransformMethod : int
46 {
47 Linear,
48 Helmert,
49 PolynomialOrder1,
50 PolynomialOrder2,
51 PolynomialOrder3,
52 ThinPlateSpline,
53 Projective,
54 InvalidTransform = 65535
55 };
56 Q_ENUM( TransformMethod )
57
59
60 virtual ~QgsGcpTransformerInterface() = default;
61
64
66 QgsGcpTransformerInterface &operator=( const QgsGcpTransformerInterface &other ) = delete;
67
75
84 virtual bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) SIP_THROW( QgsNotSupportedException ) = 0;
85
89 virtual int minimumGcpCount() const = 0;
90
94 virtual TransformMethod method() const = 0;
95
103 bool transform( double &x SIP_INOUT, double &y SIP_INOUT, bool inverseTransform = false ) const;
104
108 static QString methodToString( TransformMethod method );
109
116
125 static QgsGcpTransformerInterface *createFromParameters( TransformMethod method, const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates ) SIP_THROW( QgsNotSupportedException ) SIP_FACTORY;
126
127#ifndef SIP_RUN
128
132 virtual GDALTransformerFunc GDALTransformer() const = 0;
133
137 virtual void *GDALTransformerArgs() const = 0;
138#endif
139
140 private:
141#ifdef SIP_RUN
143#endif
144};
145
153{
154 public:
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, double *x, double *y, double *z, int *panSuccess );
179};
180
188{
189 public:
191
195 bool getOriginScaleRotation( QgsPointXY &origin, double &scale, double &rotation ) const;
196
197 QgsGcpTransformerInterface *clone() const override;
198 bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) override;
199 int minimumGcpCount() const override;
200 GDALTransformerFunc GDALTransformer() const override;
201 void *GDALTransformerArgs() const override;
202 TransformMethod method() const override;
203
204 private:
205 struct HelmertParameters
206 {
207 QgsPointXY origin;
208 double scale = 0;
209 double angle = 0;
210 bool invertYAxis = false;
211 };
212 HelmertParameters mHelmertParameters;
213
214 static int helmertTransform( void *pTransformerArg, int bDstToSrc, int nPointCount, double *x, double *y, double *z, int *panSuccess );
215};
216
224{
225 public:
227 QgsGDALGeorefTransform( bool useTPS, unsigned int polynomialOrder );
228 ~QgsGDALGeorefTransform() override;
229
230 QgsGcpTransformerInterface *clone() const override;
231 bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) override;
232 int minimumGcpCount() const override;
233 GDALTransformerFunc GDALTransformer() const override;
234 void *GDALTransformerArgs() const override;
235 TransformMethod method() const override;
236
237 private:
238 void destroyGdalArgs();
239
240 QVector<QgsPointXY> mSourceCoords;
241 QVector<QgsPointXY> mDestCoordinates;
242 bool mInvertYAxis = false;
243
244 const int mPolynomialOrder;
245 const bool mIsTPSTransform;
246
247 void *mGDALTransformerArgs = nullptr;
248};
249
260{
261 public:
263
264 QgsGcpTransformerInterface *clone() const override;
265 bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) override;
266 int minimumGcpCount() const override;
267 GDALTransformerFunc GDALTransformer() const override;
268 void *GDALTransformerArgs() const override;
269 TransformMethod method() const override;
270
271 private:
272 struct ProjectiveParameters
273 {
274 double H[9]; // Homography
275 double Hinv[9]; // Inverted homography
276 bool hasInverse; // Could the inverted homography be calculated?
277 } mParameters;
278
279 static int projectiveTransform( void *pTransformerArg, int bDstToSrc, int nPointCount, double *x, double *y, double *z, int *panSuccess );
280};
281
282#endif //QGSGCPTRANSFORMER_H
int minimumGcpCount() const override
Returns the minimum number of Ground Control Points (GCPs) required for parameter fitting.
TransformMethod method() const override
Returns the transformation method.
QgsGcpTransformerInterface * clone() const override
Clones the transformer, returning a new copy of the transformer with the same parameters as this one.
QgsGDALGeorefTransform(bool useTPS, unsigned int polynomialOrder)
Constructor for QgsGDALGeorefTransform.
GDALTransformerFunc GDALTransformer() const override
Returns function pointer to the GDALTransformer function.
void * GDALTransformerArgs() const override
Returns pointer to the GDALTransformer arguments.
bool updateParametersFromGcps(const QVector< QgsPointXY > &sourceCoordinates, const QVector< QgsPointXY > &destinationCoordinates, bool invertYAxis=false) override
Fits transformation parameters using the specified Ground Control Points (GCPs) lists of source and d...
bool transform(double &x, double &y, bool inverseTransform=false) const
Transforms the point (x, y) from source to destination coordinates.
TransformMethod
Available transformation methods.
static QgsGcpTransformerInterface * create(TransformMethod method)
Creates a new QgsGcpTransformerInterface subclass representing the specified transform method.
virtual QgsGcpTransformerInterface * clone() const =0
Clones the transformer, returning a new copy of the transformer with the same parameters as this one.
QgsGcpTransformerInterface()=default
static QString methodToString(TransformMethod method)
Returns a translated string representing the specified transform method.
virtual void * GDALTransformerArgs() const =0
Returns pointer to the GDALTransformer arguments.
virtual int minimumGcpCount() const =0
Returns the minimum number of Ground Control Points (GCPs) required for parameter fitting.
virtual GDALTransformerFunc GDALTransformer() const =0
Returns function pointer to the GDALTransformer function.
virtual TransformMethod method() const =0
Returns the transformation method.
static QgsGcpTransformerInterface * createFromParameters(TransformMethod method, const QVector< QgsPointXY > &sourceCoordinates, const QVector< QgsPointXY > &destinationCoordinates)
Creates a new QgsGcpTransformerInterface subclass representing the specified transform method,...
virtual bool updateParametersFromGcps(const QVector< QgsPointXY > &sourceCoordinates, const QVector< QgsPointXY > &destinationCoordinates, bool invertYAxis=false)=0
Fits transformation parameters using the specified Ground Control Points (GCPs) lists of source and d...
TransformMethod method() const override
Returns the transformation method.
QgsGcpTransformerInterface * clone() const override
Clones the transformer, returning a new copy of the transformer with the same parameters as this one.
bool getOriginScaleRotation(QgsPointXY &origin, double &scale, double &rotation) const
Returns the origin, scale and rotation for the transform.
QgsHelmertGeorefTransform()=default
GDALTransformerFunc GDALTransformer() const override
Returns function pointer to the GDALTransformer function.
int minimumGcpCount() const override
Returns the minimum number of Ground Control Points (GCPs) required for parameter fitting.
bool updateParametersFromGcps(const QVector< QgsPointXY > &sourceCoordinates, const QVector< QgsPointXY > &destinationCoordinates, bool invertYAxis=false) override
Fits transformation parameters using the specified Ground Control Points (GCPs) lists of source and d...
void * GDALTransformerArgs() const override
Returns pointer to the GDALTransformer arguments.
bool getOriginScale(QgsPointXY &origin, double &scaleX, double &scaleY) const
Returns the origin and scale for the transform.
TransformMethod method() const override
Returns the transformation method.
void * GDALTransformerArgs() const override
Returns pointer to the GDALTransformer arguments.
QgsGcpTransformerInterface * clone() const override
Clones the transformer, returning a new copy of the transformer with the same parameters as this one.
QgsLinearGeorefTransform()=default
bool updateParametersFromGcps(const QVector< QgsPointXY > &sourceCoordinates, const QVector< QgsPointXY > &destinationCoordinates, bool invertYAxis=false) override
Fits transformation parameters using the specified Ground Control Points (GCPs) lists of source and d...
int minimumGcpCount() const override
Returns the minimum number of Ground Control Points (GCPs) required for parameter fitting.
GDALTransformerFunc GDALTransformer() const override
Returns function pointer to the GDALTransformer function.
Custom exception class which is raised when an operation is not supported.
Represents a 2D point.
Definition qgspointxy.h:60
int minimumGcpCount() const override
Returns the minimum number of Ground Control Points (GCPs) required for parameter fitting.
QgsGcpTransformerInterface * clone() const override
Clones the transformer, returning a new copy of the transformer with the same parameters as this one.
bool updateParametersFromGcps(const QVector< QgsPointXY > &sourceCoordinates, const QVector< QgsPointXY > &destinationCoordinates, bool invertYAxis=false) override
Fits transformation parameters using the specified Ground Control Points (GCPs) lists of source and d...
GDALTransformerFunc GDALTransformer() const override
Returns function pointer to the GDALTransformer function.
void * GDALTransformerArgs() const override
Returns pointer to the GDALTransformer arguments.
TransformMethod method() const override
Returns the transformation method.
#define SIP_SKIP
Definition qgis_sip.h:134
#define SIP_ABSTRACT
Definition qgis_sip.h:221
#define SIP_FACTORY
Definition qgis_sip.h:84
#define SIP_INOUT
Definition qgis_sip.h:79
#define SIP_THROW(name,...)
Definition qgis_sip.h:211