QGIS API Documentation 4.1.0-Master (60fea48833c)
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(
85 ) = 0;
86
90 virtual int minimumGcpCount() const = 0;
91
95 virtual TransformMethod method() const = 0;
96
104 bool transform( double &x SIP_INOUT, double &y SIP_INOUT, bool inverseTransform = false ) const;
105
109 static QString methodToString( TransformMethod method );
110
117
126 static QgsGcpTransformerInterface *createFromParameters( TransformMethod method, const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates ) SIP_THROW(
128 ) SIP_FACTORY;
129
130#ifndef SIP_RUN
131
135 virtual GDALTransformerFunc GDALTransformer() const = 0;
136
140 virtual void *GDALTransformerArgs() const = 0;
141#endif
142
143 private:
144#ifdef SIP_RUN
146#endif
147};
148
156{
157 public:
159
163 bool getOriginScale( QgsPointXY &origin, double &scaleX, double &scaleY ) const;
164
165 QgsGcpTransformerInterface *clone() const override;
166 bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) override;
167 int minimumGcpCount() const override;
168 GDALTransformerFunc GDALTransformer() const override;
169 void *GDALTransformerArgs() const override;
170 TransformMethod method() const override;
171
172 private:
173 struct LinearParameters
174 {
175 QgsPointXY origin;
176 double scaleX = 1;
177 double scaleY = 1;
178 bool invertYAxis = false;
179 } mParameters;
180
181 static int linearTransform( void *pTransformerArg, int bDstToSrc, int nPointCount, double *x, double *y, double *z, int *panSuccess );
182};
183
191{
192 public:
194
198 bool getOriginScaleRotation( QgsPointXY &origin, double &scale, double &rotation ) const;
199
200 QgsGcpTransformerInterface *clone() const override;
201 bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) override;
202 int minimumGcpCount() const override;
203 GDALTransformerFunc GDALTransformer() const override;
204 void *GDALTransformerArgs() const override;
205 TransformMethod method() const override;
206
207 private:
208 struct HelmertParameters
209 {
210 QgsPointXY origin;
211 double scale = 0;
212 double angle = 0;
213 bool invertYAxis = false;
214 };
215 HelmertParameters mHelmertParameters;
216
217 static int helmertTransform( void *pTransformerArg, int bDstToSrc, int nPointCount, double *x, double *y, double *z, int *panSuccess );
218};
219
227{
228 public:
230 QgsGDALGeorefTransform( bool useTPS, unsigned int polynomialOrder );
231 ~QgsGDALGeorefTransform() override;
232
233 QgsGcpTransformerInterface *clone() const override;
234 bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) override;
235 int minimumGcpCount() const override;
236 GDALTransformerFunc GDALTransformer() const override;
237 void *GDALTransformerArgs() const override;
238 TransformMethod method() const override;
239
240 private:
241 void destroyGdalArgs();
242
243 QVector<QgsPointXY> mSourceCoords;
244 QVector<QgsPointXY> mDestCoordinates;
245 bool mInvertYAxis = false;
246
247 const int mPolynomialOrder;
248 const bool mIsTPSTransform;
249
250 void *mGDALTransformerArgs = nullptr;
251};
252
263{
264 public:
266
267 QgsGcpTransformerInterface *clone() const override;
268 bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) override;
269 int minimumGcpCount() const override;
270 GDALTransformerFunc GDALTransformer() const override;
271 void *GDALTransformerArgs() const override;
272 TransformMethod method() const override;
273
274 private:
275 struct ProjectiveParameters
276 {
277 double H[9]; // Homography
278 double Hinv[9]; // Inverted homography
279 bool hasInverse; // Could the inverted homography be calculated?
280 } mParameters;
281
282 static int projectiveTransform( void *pTransformerArg, int bDstToSrc, int nPointCount, double *x, double *y, double *z, int *panSuccess );
283};
284
285#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:62
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:133
#define SIP_ABSTRACT
Definition qgis_sip.h:220
#define SIP_FACTORY
Definition qgis_sip.h:83
#define SIP_INOUT
Definition qgis_sip.h:78
#define SIP_THROW(name,...)
Definition qgis_sip.h:210