QGIS API Documentation  3.20.0-Odense (decaadbb31)
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  public:
36 
40  enum class TransformMethod : int
41  {
42  Linear,
43  Helmert,
44  PolynomialOrder1,
45  PolynomialOrder2,
46  PolynomialOrder3,
47  ThinPlateSpline,
48  Projective,
49  InvalidTransform = 65535
50  };
51 
54 
55  virtual ~QgsGcpTransformerInterface() = default;
56 
59 
62 
70 
79  virtual bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) SIP_THROW( QgsNotSupportedException ) = 0;
80 
84  virtual int minimumGcpCount() const = 0;
85 
89  virtual TransformMethod method() const = 0;
90 
98  bool transform( double &x SIP_INOUT, double &y SIP_INOUT, bool inverseTransform = false ) const;
99 
103  static QString methodToString( TransformMethod method );
104 
110  static QgsGcpTransformerInterface *create( TransformMethod method ) SIP_FACTORY;
111 
120  static QgsGcpTransformerInterface *createFromParameters( TransformMethod method, const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates ) SIP_THROW( QgsNotSupportedException ) SIP_FACTORY;
121 
122 #ifndef SIP_RUN
123 
127  virtual GDALTransformerFunc GDALTransformer() const = 0;
128 
132  virtual void *GDALTransformerArgs() const = 0;
133 #endif
134 
135  private:
136 
137 #ifdef SIP_RUN
139 #endif
140 };
141 
149 {
150  public:
151 
154 
158  bool getOriginScale( QgsPointXY &origin, double &scaleX, double &scaleY ) const;
159 
160  QgsGcpTransformerInterface *clone() const override;
161  bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) override;
162  int minimumGcpCount() const override;
163  GDALTransformerFunc GDALTransformer() const override;
164  void *GDALTransformerArgs() const override;
165  TransformMethod method() const override;
166 
167  private:
168  struct LinearParameters
169  {
170  QgsPointXY origin;
171  double scaleX = 1;
172  double scaleY = 1;
173  bool invertYAxis = false;
174  } mParameters;
175 
176  static int linearTransform( void *pTransformerArg, int bDstToSrc, int nPointCount,
177  double *x, double *y, double *z, int *panSuccess );
178 
179 };
180 
188 {
189  public:
190 
193 
197  bool getOriginScaleRotation( QgsPointXY &origin, double &scale, double &rotation ) const;
198 
199  QgsGcpTransformerInterface *clone() const override;
200  bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) override;
201  int minimumGcpCount() const override;
202  GDALTransformerFunc GDALTransformer() const override;
203  void *GDALTransformerArgs() const override;
204  TransformMethod method() const override;
205 
206  private:
207 
208  struct HelmertParameters
209  {
210  QgsPointXY origin;
211  double scale;
212  double angle;
213  bool invertYAxis = false;
214  };
215  HelmertParameters mHelmertParameters;
216 
217  static int helmertTransform( void *pTransformerArg, int bDstToSrc, int nPointCount,
218  double *x, double *y, double *z, int *panSuccess );
219 
220 };
221 
229 {
230  public:
231 
233  QgsGDALGeorefTransform( bool useTPS, unsigned int polynomialOrder );
234  ~QgsGDALGeorefTransform() override;
235 
236  QgsGcpTransformerInterface *clone() const override;
237  bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) override;
238  int minimumGcpCount() const override;
239  GDALTransformerFunc GDALTransformer() const override;
240  void *GDALTransformerArgs() const override;
241  TransformMethod method() const override;
242 
243  private:
244  void destroyGdalArgs();
245 
246  QVector<QgsPointXY> mSourceCoords;
247  QVector<QgsPointXY> mDestCoordinates;
248  bool mInvertYAxis = false;
249 
250  const int mPolynomialOrder;
251  const bool mIsTPSTransform;
252 
253  void *mGDALTransformerArgs = nullptr;
254 
255 };
256 
267 {
268  public:
269 
272 
273  QgsGcpTransformerInterface *clone() const override;
274  bool updateParametersFromGcps( const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates, bool invertYAxis = false ) override;
275  int minimumGcpCount() const override;
276  GDALTransformerFunc GDALTransformer() const override;
277  void *GDALTransformerArgs() const override;
278  TransformMethod method() const override;
279 
280  private:
281  struct ProjectiveParameters
282  {
283  double H[9]; // Homography
284  double Hinv[9]; // Inverted homography
285  bool hasInverse; // Could the inverted homography be calculated?
286  } mParameters;
287 
288  static int projectiveTransform( void *pTransformerArg, int bDstToSrc, int nPointCount,
289  double *x, double *y, double *z, int *panSuccess );
290 
291 };
292 
293 #endif //QGSGCPTRANSFORMER_H
Interface to gdal thin plate splines and 1st/2nd/3rd order polynomials.
An interface for Ground Control Points (GCP) based transformations.
QgsGcpTransformerInterface(const QgsGcpTransformerInterface &other)=delete
QgsGcpTransformerInterface cannot be copied - use clone() instead.
TransformMethod
Available transformation methods.
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...
QgsGcpTransformerInterface & operator=(const QgsGcpTransformerInterface &other)=delete
QgsGcpTransformerInterface cannot be copied - use clone() instead.
virtual QgsGcpTransformerInterface * clone() const =0
Clones the transformer, returning a new copy of the transformer with the same parameters as this one.
QgsGcpTransformerInterface()=default
Constructor for QgsGcpTransformerInterface.
virtual void * GDALTransformerArgs() const =0
Returns pointer to the GDALTransformer arguments.
virtual GDALTransformerFunc GDALTransformer() const =0
Returns function pointer to the GDALTransformer function.
virtual ~QgsGcpTransformerInterface()=default
2-dimensional helmert transform, parametrised by isotropic scale, rotation angle and translation.
QgsHelmertGeorefTransform()=default
Constructor for QgsHelmertGeorefTransform.
A simple transform which is parametrized by a translation and anistotropic scale.
QgsLinearGeorefTransform()=default
Constructor for QgsLinearGeorefTransform.
Custom exception class which is raised when an operation is not supported.
Definition: qgsexception.h:118
A class to represent a 2D point.
Definition: qgspointxy.h:59
A planar projective transform, expressed by a homography.
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
#define SIP_THROW(name)
Definition: qgis_sip.h:189
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_ABSTRACT
Definition: qgis_sip.h:199
#define SIP_FACTORY
Definition: qgis_sip.h:76
#define SIP_INOUT
Definition: qgis_sip.h:71