QGIS API Documentation  2.0.1-Dufour
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:
48  QgsRectangle theDestExtent,
49  int theDestRows, int theDestCols,
50  double theMaxSrcXRes, double theMaxSrcYRes,
51  QgsRectangle theExtent
52  );
56  double theMaxSrcXRes, double theMaxSrcYRes,
57  QgsRectangle theExtent
58  );
61  // To avoid synthesized which fails on copy of QgsCoordinateTransform
62  // (QObject child) in Python bindings
63  QgsRasterProjector( const QgsRasterProjector &projector );
64
67
68  QgsRasterProjector & operator=( const QgsRasterProjector &projector );
69
70  QgsRasterInterface *clone() const;
71
72  int bandCount() const;
73
74  QGis::DataType dataType( int bandNo ) const;
75
77  void setCRS( const QgsCoordinateReferenceSystem & theSrcCRS, const QgsCoordinateReferenceSystem & theDestCRS );
78
80  QgsCoordinateReferenceSystem srcCrs() const { return mSrcCRS; }
81
83  QgsCoordinateReferenceSystem destCrs() const { return mDestCRS; }
84
86  void setMaxSrcRes( double theMaxSrcXRes, double theMaxSrcYRes )
87  {
88  mMaxSrcXRes = theMaxSrcXRes; mMaxSrcYRes = theMaxSrcYRes;
89  }
90
91  QgsRasterBlock *block( int bandNo, const QgsRectangle & extent, int width, int height );
92
93  private:
95  QgsRectangle srcExtent() { return mSrcExtent; }
96
98  int srcRows() { return mSrcRows; }
99  int srcCols() { return mSrcCols; }
100  void setSrcRows( int theRows ) { mSrcRows = theRows; mSrcXRes = mSrcExtent.height() / mSrcRows; }
101  void setSrcCols( int theCols ) { mSrcCols = theCols; mSrcYRes = mSrcExtent.width() / mSrcCols; }
102
104  void srcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol );
105
106  int dstRows() const { return mDestRows; }
107  int dstCols() const { return mDestCols; }
108
110  void destPointOnCPMatrix( int theRow, int theCol, double *theX, double *theY );
111
113  int matrixRow( int theDestRow );
114  int matrixCol( int theDestCol );
115
117  QgsPoint srcPoint( int theRow, int theCol );
118
120  inline void preciseSrcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol );
121
123  inline void approximateSrcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol );
124
126  void calc();
127
129  void insertRows();
130
132  void insertCols();
133
134  /* calculate single control point in current matrix */
135  void calcCP( int theRow, int theCol );
136
138  bool calcRow( int theRow );
139
141  bool calcCol( int theCol );
142
144  void calcSrcExtent();
145
147  void calcSrcRowsCols();
148
151  bool checkCols();
152
155  bool checkRows();
156
158  void calcHelper( int theMatrixRow, QgsPoint *thePoints );
159
161  void nextHelper();
162
164  QString cpToString();
165
168
171
174
177
180
183
186
189
191  double mDestXRes;
192
194  double mDestYRes;
195
197  int mSrcRows;
198
200  int mSrcCols;
201
203  double mSrcXRes;
204
206  double mSrcYRes;
207
210
213
215  QList< QList<QgsPoint> > mCPMatrix;
216
218  /* Same size as mCPMatrix */
219  QList< QList<bool> > mCPLegalMatrix;
220
222  /* Warning: using QList is slow on access */
224
226  /* Warning: using QList is slow on access */
228
231
233  int mCPCols;
235  int mCPRows;
236
239
241  double mMaxSrcXRes;
242  double mMaxSrcYRes;
243
246 };
247
248 #endif
249