QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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:
44 enum class TransformMethod : int
45 {
46 Linear,
47 Helmert,
48 PolynomialOrder1,
49 PolynomialOrder2,
50 PolynomialOrder3,
51 ThinPlateSpline,
52 Projective,
53 InvalidTransform = 65535
54 };
55 Q_ENUM( TransformMethod )
56
58
59 virtual ~QgsGcpTransformerInterface() = default;
60
63
65 QgsGcpTransformerInterface &operator=( const QgsGcpTransformerInterface &other ) = delete;
66
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#ifdef SIP_RUN
142#endif
143};
144
152{
153 public:
155
159 bool getOriginScale( QgsPointXY &origin, double &scaleX, double &scaleY ) const;
160
161 QgsGcpTransformerInterface *clone() const override;
162 bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) override;
163 int minimumGcpCount() const override;
164 GDALTransformerFunc GDALTransformer() const override;
165 void *GDALTransformerArgs() const override;
166 TransformMethod method() const override;
167
168 private:
169 struct LinearParameters
170 {
171 QgsPointXY origin;
172 double scaleX = 1;
173 double scaleY = 1;
174 bool invertYAxis = false;
175 } mParameters;
176
177 static int linearTransform( void *pTransformerArg, int bDstToSrc, int nPointCount, double *x, double *y, double *z, int *panSuccess );
178};
179
187{
188 public:
190
194 bool getOriginScaleRotation( QgsPointXY &origin, double &scale, double &rotation ) const;
195
196 QgsGcpTransformerInterface *clone() const override;
197 bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) override;
198 int minimumGcpCount() const override;
199 GDALTransformerFunc GDALTransformer() const override;
200 void *GDALTransformerArgs() const override;
201 TransformMethod method() const override;
202
203 private:
204 struct HelmertParameters
205 {
206 QgsPointXY origin;
207 double scale = 0;
208 double angle = 0;
209 bool invertYAxis = false;
210 };
211 HelmertParameters mHelmertParameters;
212
213 static int helmertTransform( void *pTransformerArg, int bDstToSrc, int nPointCount, double *x, double *y, double *z, int *panSuccess );
214};
215
223{
224 public:
226 QgsGDALGeorefTransform( bool useTPS, unsigned int polynomialOrder );
227 ~QgsGDALGeorefTransform() override;
228
229 QgsGcpTransformerInterface *clone() const override;
230 bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) override;
231 int minimumGcpCount() const override;
232 GDALTransformerFunc GDALTransformer() const override;
233 void *GDALTransformerArgs() const override;
234 TransformMethod method() const override;
235
236 private:
237 void destroyGdalArgs();
238
239 QVector<QgsPointXY> mSourceCoords;
240 QVector<QgsPointXY> mDestCoordinates;
241 bool mInvertYAxis = false;
242
243 const int mPolynomialOrder;
244 const bool mIsTPSTransform;
245
246 void *mGDALTransformerArgs = nullptr;
247};
248
259{
260 public:
262
263 QgsGcpTransformerInterface *clone() const override;
264 bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) override;
265 int minimumGcpCount() const override;
266 GDALTransformerFunc GDALTransformer() const override;
267 void *GDALTransformerArgs() const override;
268 TransformMethod method() const override;
269
270 private:
271 struct ProjectiveParameters
272 {
273 double H[9]; // Homography
274 double Hinv[9]; // Inverted homography
275 bool hasInverse; // Could the inverted homography be calculated?
276 } mParameters;
277
278 static int projectiveTransform( void *pTransformerArg, int bDstToSrc, int nPointCount, double *x, double *y, double *z, int *panSuccess );
279};
280
281#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