QGIS API Documentation  2.14.0-Essen
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
38 class CORE_EXPORT QgsRasterProjector : public QgsRasterInterface
39 {
40  public:
44  enum Precision
45  {
46  Approximate = 0,
47  Exact = 1,
48  };
49
56  const QgsCoordinateReferenceSystem& theDestCRS,
57  int theSrcDatumTransform,
58  int theDestDatumTransform,
59  const QgsRectangle& theDestExtent,
60  int theDestRows, int theDestCols,
61  double theMaxSrcXRes, double theMaxSrcYRes,
62  const QgsRectangle& theExtent
63  );
64
66  const QgsCoordinateReferenceSystem& theDestCRS,
67  const QgsRectangle& theDestExtent,
68  int theDestRows, int theDestCols,
69  double theMaxSrcXRes, double theMaxSrcYRes,
70  const QgsRectangle& theExtent
71  );
73  const QgsCoordinateReferenceSystem& theDestCRS,
74  double theMaxSrcXRes, double theMaxSrcYRes,
75  const QgsRectangle& theExtent
76  );
79  // To avoid synthesized which fails on copy of QgsCoordinateTransform
80  // (QObject child) in Python bindings
81  QgsRasterProjector( const QgsRasterProjector &projector );
82
85
86  QgsRasterProjector & operator=( const QgsRasterProjector &projector );
87
88  QgsRasterProjector *clone() const override;
89
90  int bandCount() const override;
91
92  QGis::DataType dataType( int bandNo ) const override;
93
95  void setCRS( const QgsCoordinateReferenceSystem & theSrcCRS, const QgsCoordinateReferenceSystem & theDestCRS,
96  int srcDatumTransform = -1, int destDatumTransform = -1 );
97
99  QgsCoordinateReferenceSystem srcCrs() const { return mSrcCRS; }
100
102  QgsCoordinateReferenceSystem destCrs() const { return mDestCRS; }
103
105  void setMaxSrcRes( double theMaxSrcXRes, double theMaxSrcYRes )
106  {
107  mMaxSrcXRes = theMaxSrcXRes;
108  mMaxSrcYRes = theMaxSrcYRes;
109  }
110
111  Precision precision() const { return mPrecision; }
112  void setPrecision( Precision precision ) { mPrecision = precision; }
113  // Translated precision mode, for use in ComboBox etc.
114  static QString precisionLabel( Precision precision );
115
116  QgsRasterBlock *block( int bandNo, const QgsRectangle & extent, int width, int height ) override;
117
119  bool destExtentSize( const QgsRectangle& theSrcExtent, int theSrcXSize, int theSrcYSize,
120  QgsRectangle& theDestExtent, int& theDestXSize, int& theDestYSize );
121
123  static bool extentSize( const QgsCoordinateTransform* ct,
124  const QgsRectangle& theSrcExtent, int theSrcXSize, int theSrcYSize,
125  QgsRectangle& theDestExtent, int& theDestXSize, int& theDestYSize );
126
127  private:
129  QgsRectangle srcExtent() { return mSrcExtent; }
130
132  int srcRows() { return mSrcRows; }
133  int srcCols() { return mSrcCols; }
134  void setSrcRows( int theRows ) { mSrcRows = theRows; mSrcXRes = mSrcExtent.height() / mSrcRows; }
135  void setSrcCols( int theCols ) { mSrcCols = theCols; mSrcYRes = mSrcExtent.width() / mSrcCols; }
136
141  bool srcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol, const QgsCoordinateTransform* ct );
142
143  int dstRows() const { return mDestRows; }
144  int dstCols() const { return mDestCols; }
145
147  void destPointOnCPMatrix( int theRow, int theCol, double *theX, double *theY );
148
150  int matrixRow( int theDestRow );
151  int matrixCol( int theDestCol );
152
154  QgsPoint srcPoint( int theRow, int theCol );
155
157  inline bool preciseSrcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol, const QgsCoordinateTransform* ct );
158
160  inline bool approximateSrcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol );
161
163  void calc();
164
166  void insertRows( const QgsCoordinateTransform* ct );
167
169  void insertCols( const QgsCoordinateTransform* ct );
170
172  void calcCP( int theRow, int theCol, const QgsCoordinateTransform* ct );
173
175  bool calcRow( int theRow, const QgsCoordinateTransform* ct );
176
178  bool calcCol( int theCol, const QgsCoordinateTransform* ct );
179
181  void calcSrcExtent();
182
184  void calcSrcRowsCols();
185
188  bool checkCols( const QgsCoordinateTransform* ct );
189
192  bool checkRows( const QgsCoordinateTransform* ct );
193
195  void calcHelper( int theMatrixRow, QgsPoint *thePoints );
196
198  void nextHelper();
199
201  QString cpToString();
202
205
208
210  int mSrcDatumTransform;
211
213  int mDestDatumTransform;
214
216  QgsRectangle mDestExtent;
217
219  QgsRectangle mSrcExtent;
220
222  QgsRectangle mExtent;
223
225  int mDestRows;
226
228  int mDestCols;
229
231  double mDestXRes;
232
234  double mDestYRes;
235
237  int mSrcRows;
238
240  int mSrcCols;
241
243  double mSrcXRes;
244
246  double mSrcYRes;
247
249  double mDestRowsPerMatrixRow;
250
252  double mDestColsPerMatrixCol;
253
255  QList< QList<QgsPoint> > mCPMatrix;
256
258  /* Same size as mCPMatrix */
259  QList< QList<bool> > mCPLegalMatrix;
260
262  /* Warning: using QList is slow on access */
263  QgsPoint *pHelperTop;
264
266  /* Warning: using QList is slow on access */
267  QgsPoint *pHelperBottom;
268
270  int mHelperTopRow;
271
273  int mCPCols;
275  int mCPRows;
276
278  double mSqrTolerance;
279
281  double mMaxSrcXRes;
282  double mMaxSrcYRes;
283
285  Precision mPrecision;
286
289  bool mApproximate;
290 };
291
292 #endif
293
virtual int bandCount() const =0
Get number of bands.
void setMaxSrcRes(double theMaxSrcXRes, double theMaxSrcYRes)
set maximum source resolution
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Precision precision() const
Raster data container.
QgsCoordinateReferenceSystem destCrs() const
Get destination CRS.
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:65
void setPrecision(Precision precision)
QgsCoordinateReferenceSystem srcCrs() const
Get source CRS.
Precision
Precison defines if each pixel is reprojected or approximate reprojection based on an approximation m...
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:129
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.
double height() const
Height of the rectangle.
Definition: qgsrectangle.h:212