QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 #include "qgspoint.h"
21 #include "qgis_analysis.h"
22 #include "qgis_sip.h"
23 
34 {
35  Q_GADGET
36 
37  public:
38 
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 
55 
56  QgsGcpTransformerInterface() = default;
57 
58  virtual ~QgsGcpTransformerInterface() = default;
59 
62 
64  QgsGcpTransformerInterface &operator=( const QgsGcpTransformerInterface &other ) = delete;
65 
72  virtual QgsGcpTransformerInterface *clone() const = 0 SIP_FACTORY;
73 
82  virtual bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) SIP_THROW( QgsNotSupportedException ) = 0;
83 
87  virtual int minimumGcpCount() const = 0;
88 
92  virtual TransformMethod method() const = 0;
93 
101  bool transform( double &x SIP_INOUT, double &y SIP_INOUT, bool inverseTransform = false ) const;
102 
106  static QString methodToString( TransformMethod method );
107 
113  static QgsGcpTransformerInterface *create( TransformMethod method ) SIP_FACTORY;
114 
123  static QgsGcpTransformerInterface *createFromParameters( TransformMethod method, const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates ) SIP_THROW( QgsNotSupportedException ) SIP_FACTORY;
124 
125 #ifndef SIP_RUN
126 
130  virtual GDALTransformerFunc GDALTransformer() const = 0;
131 
135  virtual void *GDALTransformerArgs() const = 0;
136 #endif
137 
138  private:
139 
140 #ifdef SIP_RUN
142 #endif
143 };
144 
152 {
153  public:
154 
156  QgsLinearGeorefTransform() = default;
157 
161  bool getOriginScale( QgsPointXY &origin, double &scaleX, double &scaleY ) const;
162 
163  QgsGcpTransformerInterface *clone() const override;
164  bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) override;
165  int minimumGcpCount() const override;
166  GDALTransformerFunc GDALTransformer() const override;
167  void *GDALTransformerArgs() const override;
168  TransformMethod method() const override;
169 
170  private:
171  struct LinearParameters
172  {
173  QgsPointXY origin;
174  double scaleX = 1;
175  double scaleY = 1;
176  bool invertYAxis = false;
177  } mParameters;
178 
179  static int linearTransform( void *pTransformerArg, int bDstToSrc, int nPointCount,
180  double *x, double *y, double *z, int *panSuccess );
181 
182 };
183 
191 {
192  public:
193 
195  QgsHelmertGeorefTransform() = default;
196 
200  bool getOriginScaleRotation( QgsPointXY &origin, double &scale, double &rotation ) const;
201 
202  QgsGcpTransformerInterface *clone() const override;
203  bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) override;
204  int minimumGcpCount() const override;
205  GDALTransformerFunc GDALTransformer() const override;
206  void *GDALTransformerArgs() const override;
207  TransformMethod method() const override;
208 
209  private:
210 
211  struct HelmertParameters
212  {
213  QgsPointXY origin;
214  double scale;
215  double angle;
216  bool invertYAxis = false;
217  };
218  HelmertParameters mHelmertParameters;
219 
220  static int helmertTransform( void *pTransformerArg, int bDstToSrc, int nPointCount,
221  double *x, double *y, double *z, int *panSuccess );
222 
223 };
224 
232 {
233  public:
234 
236  QgsGDALGeorefTransform( bool useTPS, unsigned int polynomialOrder );
237  ~QgsGDALGeorefTransform() override;
238 
239  QgsGcpTransformerInterface *clone() const override;
240  bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) override;
241  int minimumGcpCount() const override;
242  GDALTransformerFunc GDALTransformer() const override;
243  void *GDALTransformerArgs() const override;
244  TransformMethod method() const override;
245 
246  private:
247  void destroyGdalArgs();
248 
249  QVector<QgsPointXY> mSourceCoords;
250  QVector<QgsPointXY> mDestCoordinates;
251  bool mInvertYAxis = false;
252 
253  const int mPolynomialOrder;
254  const bool mIsTPSTransform;
255 
256  void *mGDALTransformerArgs = nullptr;
257 
258 };
259 
270 {
271  public:
272 
275 
276  QgsGcpTransformerInterface *clone() const override;
277  bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) override;
278  int minimumGcpCount() const override;
279  GDALTransformerFunc GDALTransformer() const override;
280  void *GDALTransformerArgs() const override;
281  TransformMethod method() const override;
282 
283  private:
284  struct ProjectiveParameters
285  {
286  double H[9]; // Homography
287  double Hinv[9]; // Inverted homography
288  bool hasInverse; // Could the inverted homography be calculated?
289  } mParameters;
290 
291  static int projectiveTransform( void *pTransformerArg, int bDstToSrc, int nPointCount,
292  double *x, double *y, double *z, int *panSuccess );
293 
294 };
295 
296 #endif //QGSGCPTRANSFORMER_H
QgsGcpTransformerInterface::clone
virtual QgsGcpTransformerInterface * clone() const =0
Clones the transformer, returning a new copy of the transformer with the same parameters as this one.
QgsLinearGeorefTransform
A simple transform which is parametrized by a translation and anistotropic scale.
Definition: qgsgcptransformer.h:151
QgsGcpTransformerInterface::updateParametersFromGcps
virtual bool updateParametersFromGcps(const QVector< QgsPointXY > &sourceCoordinates, const QVector< QgsPointXY > &destinationCoordinates, bool invertYAxis=false) SIP_THROW(QgsNotSupportedException)=0
Fits transformation parameters using the specified Ground Control Points (GCPs) lists of source and d...
qgspoint.h
QgsProjectiveGeorefTransform
A planar projective transform, expressed by a homography.
Definition: qgsgcptransformer.h:269
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsHelmertGeorefTransform
2-dimensional helmert transform, parametrised by isotropic scale, rotation angle and translation.
Definition: qgsgcptransformer.h:190
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
SIP_THROW
#define SIP_THROW(name)
Definition: qgis_sip.h:198
qgis_sip.h
QgsGcpTransformerInterface::method
virtual TransformMethod method() const =0
Returns the transformation method.
QgsGDALGeorefTransform
Interface to gdal thin plate splines and 1st/2nd/3rd order polynomials.
Definition: qgsgcptransformer.h:231
SIP_INOUT
#define SIP_INOUT
Definition: qgis_sip.h:71
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:58
QgsGcpTransformerInterface::GDALTransformerArgs
virtual void * GDALTransformerArgs() const =0
Returns pointer to the GDALTransformer arguments.
QgsGcpTransformerInterface::TransformMethod
TransformMethod
Available transformation methods.
Definition: qgsgcptransformer.h:55
QgsNotSupportedException
Custom exception class which is raised when an operation is not supported.
Definition: qgsexception.h:117
QgsGcpTransformerInterface::minimumGcpCount
virtual int minimumGcpCount() const =0
Returns the minimum number of Ground Control Points (GCPs) required for parameter fitting.
MathUtils::angle
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
Definition: MathUtils.cpp:786
QgsGcpTransformerInterface::GDALTransformer
virtual GDALTransformerFunc GDALTransformer() const =0
Returns function pointer to the GDALTransformer function.
QgsGcpTransformerInterface
An interface for Ground Control Points (GCP) based transformations.
Definition: qgsgcptransformer.h:33
SIP_ABSTRACT
#define SIP_ABSTRACT
Definition: qgis_sip.h:208