QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgsrasterprojector.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrasterprojector.h - Raster projector
3  --------------------------------------
4  Date : Jan 16, 2011
6  email : radim dot blazek at gmail dot com
7  ***************************************************************************/
8
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17
18 /* This code takes ideas from WarpBuilder in Geotools.
19  * Thank to Ing. Andrea Aime, Ing. Simone Giannecchini and GeoSolutions S.A.S.
20  * See : http://geo-solutions.blogspot.com/2011/01/developers-corner-improving.html
21  */
22
23 #ifndef QGSRASTERPROJECTOR_H
24 #define QGSRASTERPROJECTOR_H
25
26 #include <QVector>
27 #include <QList>
28
29 #include "qgsrectangle.h"
31 #include "qgscoordinatetransform.h"
32 #include "qgsrasterinterface.h"
33
34 #include <cmath>
35
36 class QgsPoint;
37
44 class CORE_EXPORT QgsRasterProjector : public QgsRasterInterface
45 {
46  public:
50  enum Precision
51  {
52  Approximate = 0,
53  Exact = 1,
54  };
55
57  Q_DECL_DEPRECATED
59  const QgsCoordinateReferenceSystem& theDestCRS,
60  int theSrcDatumTransform,
61  int theDestDatumTransform,
62  const QgsRectangle& theDestExtent,
63  int theDestRows, int theDestCols,
64  double theMaxSrcXRes, double theMaxSrcYRes,
65  const QgsRectangle& theExtent
66  );
68  Q_DECL_DEPRECATED
70  const QgsCoordinateReferenceSystem& theDestCRS,
71  const QgsRectangle& theDestExtent,
72  int theDestRows, int theDestCols,
73  double theMaxSrcXRes, double theMaxSrcYRes,
74  const QgsRectangle& theExtent
75  );
77  Q_DECL_DEPRECATED
79  const QgsCoordinateReferenceSystem& theDestCRS,
80  double theMaxSrcXRes, double theMaxSrcYRes,
81  const QgsRectangle& theExtent
82  );
84
88  // To avoid synthesized which fails on copy of QgsCoordinateTransform
89  // (QObject child) in Python bindings
90  Q_DECL_DEPRECATED QgsRasterProjector( const QgsRasterProjector &projector );
91
94
95  QgsRasterProjector & operator=( const QgsRasterProjector &projector );
96
97  QgsRasterProjector *clone() const override;
98
99  int bandCount() const override;
100
101  QGis::DataType dataType( int bandNo ) const override;
102
104  void setCRS( const QgsCoordinateReferenceSystem & theSrcCRS, const QgsCoordinateReferenceSystem & theDestCRS,
105  int srcDatumTransform = -1, int destDatumTransform = -1 );
106
108  QgsCoordinateReferenceSystem srcCrs() const { return mSrcCRS; }
109
111  QgsCoordinateReferenceSystem destCrs() const { return mDestCRS; }
112
114  Q_DECL_DEPRECATED void setMaxSrcRes( double theMaxSrcXRes, double theMaxSrcYRes ) { Q_UNUSED( theMaxSrcXRes ); Q_UNUSED( theMaxSrcYRes ); }
115
116  Precision precision() const { return mPrecision; }
117  void setPrecision( Precision precision ) { mPrecision = precision; }
118  // Translated precision mode, for use in ComboBox etc.
119  static QString precisionLabel( Precision precision );
120
121  QgsRasterBlock *block( int bandNo, const QgsRectangle & extent, int width, int height ) override;
122  QgsRasterBlock *block2( int bandNo, const QgsRectangle & extent, int width, int height, QgsRasterBlockFeedback* feedback = nullptr ) override;
123
125  bool destExtentSize( const QgsRectangle& theSrcExtent, int theSrcXSize, int theSrcYSize,
126  QgsRectangle& theDestExtent, int& theDestXSize, int& theDestYSize );
127
129  static bool extentSize( const QgsCoordinateTransform* ct,
130  const QgsRectangle& theSrcExtent, int theSrcXSize, int theSrcYSize,
131  QgsRectangle& theDestExtent, int& theDestXSize, int& theDestYSize );
132
133  private:
134
137
140
142  int mSrcDatumTransform;
143
145  int mDestDatumTransform;
146
148  Precision mPrecision;
149
150 };
151
153
159 class ProjectorData
160 {
161  public:
163  ProjectorData( const QgsRectangle &extent, int width, int height, QgsRasterInterface *input, const QgsCoordinateTransform *inverseCt, QgsRasterProjector::Precision precision );
164  ~ProjectorData();
165
170  bool srcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol );
171
172  QgsRectangle srcExtent() const { return mSrcExtent; }
173  int srcRows() const { return mSrcRows; }
174  int srcCols() const { return mSrcCols; }
175
176  private:
178  void destPointOnCPMatrix( int theRow, int theCol, double *theX, double *theY );
179
181  int matrixRow( int theDestRow );
182  int matrixCol( int theDestCol );
183
185  inline bool preciseSrcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol );
186
188  inline bool approximateSrcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol );
189
191  void insertRows( const QgsCoordinateTransform* ct );
192
194  void insertCols( const QgsCoordinateTransform* ct );
195
197  void calcCP( int theRow, int theCol, const QgsCoordinateTransform* ct );
198
200  bool calcRow( int theRow, const QgsCoordinateTransform* ct );
201
203  bool calcCol( int theCol, const QgsCoordinateTransform* ct );
204
206  void calcSrcExtent();
207
209  void calcSrcRowsCols();
210
213  bool checkCols( const QgsCoordinateTransform* ct );
214
217  bool checkRows( const QgsCoordinateTransform* ct );
218
220  void calcHelper( int theMatrixRow, QgsPoint *thePoints );
221
223  void nextHelper();
224
226  QString cpToString();
227
230  bool mApproximate;
231
233  QgsCoordinateTransform* mInverseCt;
234
236  QgsRectangle mDestExtent;
237
239  QgsRectangle mSrcExtent;
240
242  QgsRectangle mExtent;
243
245  int mDestRows;
246
248  int mDestCols;
249
251  double mDestXRes;
252
254  double mDestYRes;
255
257  int mSrcRows;
258
260  int mSrcCols;
261
263  double mSrcXRes;
264
266  double mSrcYRes;
267
269  double mDestRowsPerMatrixRow;
270
272  double mDestColsPerMatrixCol;
273
275  QList< QList<QgsPoint> > mCPMatrix;
276
278  /* Same size as mCPMatrix */
279  QList< QList<bool> > mCPLegalMatrix;
280
282  /* Warning: using QList is slow on access */
283  QgsPoint *pHelperTop;
284
286  /* Warning: using QList is slow on access */
287  QgsPoint *pHelperBottom;
288
290  int mHelperTopRow;
291
293  int mCPCols;
295  int mCPRows;
296
298  double mSqrTolerance;
299
301  double mMaxSrcXRes;
302  double mMaxSrcYRes;
303
304 };
305
307
308 #endif
309
virtual int bandCount() const =0
Get number of bands.
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Precision precision() const
Q_DECL_DEPRECATED void setMaxSrcRes(double theMaxSrcXRes, double theMaxSrcYRes)
QgsCoordinateReferenceSystem srcCrs() const
Get source CRS.
virtual QgsRasterBlock * block2(int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback=nullptr)
Read block of data using given extent and size.
QgsCoordinateReferenceSystem destCrs() const
Get destination CRS.
Raster data container.
virtual QGis::DataType dataType(int bandNo) const =0
Returns data type for the band specified by number.
Base class for processing filters like renderers, reprojector, resampler etc.
A class to represent a point.
Definition: qgspoint.h:117
void setPrecision(Precision precision)
QgsRasterProjector implements approximate projection support for it calculates grid of points in sour...
Precision
Precision defines if each pixel is reprojected or approximate reprojection based on an approximation ...
virtual QgsRasterInterface * clone() const =0
Clone itself, create deep copy.
Class for storing a coordinate reference system (CRS)
DataType
Raster data types.
Definition: qgis.h:133
virtual QgsRasterBlock * block(int bandNo, const QgsRectangle &extent, int width, int height)=0
Read block of data using given extent and size.
Class for doing transforms between two map coordinate systems.
Feedback object tailored for raster block reading.