QGIS API Documentation  2.2.0-Valmiera
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsrasterprojector.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrasterprojector.h - Raster projector
3  --------------------------------------
4  Date : Jan 16, 2011
5  Copyright : (C) 2005 by Radim Blazek
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 *
12  * it under the terms of the GNU General Public License as published by *
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:
49  int theSrcDatumTransform,
50  int theDestDatumTransform,
51  QgsRectangle theDestExtent,
52  int theDestRows, int theDestCols,
53  double theMaxSrcXRes, double theMaxSrcYRes,
54  QgsRectangle theExtent
55  );
56 
60  QgsRectangle theDestExtent,
61  int theDestRows, int theDestCols,
62  double theMaxSrcXRes, double theMaxSrcYRes,
63  QgsRectangle theExtent
64  );
68  double theMaxSrcXRes, double theMaxSrcYRes,
69  QgsRectangle theExtent
70  );
73  // To avoid synthesized which fails on copy of QgsCoordinateTransform
74  // (QObject child) in Python bindings
75  QgsRasterProjector( const QgsRasterProjector &projector );
76 
79 
80  QgsRasterProjector & operator=( const QgsRasterProjector &projector );
81 
82  QgsRasterInterface *clone() const;
83 
84  int bandCount() const;
85 
86  QGis::DataType dataType( int bandNo ) const;
87 
89  void setCRS( const QgsCoordinateReferenceSystem & theSrcCRS, const QgsCoordinateReferenceSystem & theDestCRS,
90  int srcDatumTransform = -1, int destDatumTransform = -1 );
91 
93  QgsCoordinateReferenceSystem srcCrs() const { return mSrcCRS; }
94 
96  QgsCoordinateReferenceSystem destCrs() const { return mDestCRS; }
97 
99  void setMaxSrcRes( double theMaxSrcXRes, double theMaxSrcYRes )
100  {
101  mMaxSrcXRes = theMaxSrcXRes; mMaxSrcYRes = theMaxSrcYRes;
102  }
103 
104  QgsRasterBlock *block( int bandNo, const QgsRectangle & extent, int width, int height );
105 
106  private:
108  QgsRectangle srcExtent() { return mSrcExtent; }
109 
111  int srcRows() { return mSrcRows; }
112  int srcCols() { return mSrcCols; }
113  void setSrcRows( int theRows ) { mSrcRows = theRows; mSrcXRes = mSrcExtent.height() / mSrcRows; }
114  void setSrcCols( int theCols ) { mSrcCols = theCols; mSrcYRes = mSrcExtent.width() / mSrcCols; }
115 
120  bool srcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol, const QgsCoordinateTransform* ct );
121 
122  int dstRows() const { return mDestRows; }
123  int dstCols() const { return mDestCols; }
124 
126  void destPointOnCPMatrix( int theRow, int theCol, double *theX, double *theY );
127 
129  int matrixRow( int theDestRow );
130  int matrixCol( int theDestCol );
131 
133  QgsPoint srcPoint( int theRow, int theCol );
134 
136  inline bool preciseSrcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol, const QgsCoordinateTransform* ct );
137 
139  inline bool approximateSrcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol );
140 
142  void calc();
143 
145  void insertRows( const QgsCoordinateTransform* ct );
146 
148  void insertCols( const QgsCoordinateTransform* ct );
149 
150  /* calculate single control point in current matrix */
151  void calcCP( int theRow, int theCol, const QgsCoordinateTransform* ct );
152 
154  bool calcRow( int theRow, const QgsCoordinateTransform* ct );
155 
157  bool calcCol( int theCol, const QgsCoordinateTransform* ct );
158 
160  void calcSrcExtent();
161 
163  void calcSrcRowsCols();
164 
167  bool checkCols( const QgsCoordinateTransform* ct );
168 
171  bool checkRows( const QgsCoordinateTransform* ct );
172 
174  void calcHelper( int theMatrixRow, QgsPoint *thePoints );
175 
177  void nextHelper();
178 
180  QString cpToString();
181 
184 
187 
190 
193 
196 
199 
202 
205 
208 
210  double mDestXRes;
211 
213  double mDestYRes;
214 
216  int mSrcRows;
217 
219  int mSrcCols;
220 
222  double mSrcXRes;
223 
225  double mSrcYRes;
226 
229 
232 
234  QList< QList<QgsPoint> > mCPMatrix;
235 
237  /* Same size as mCPMatrix */
238  QList< QList<bool> > mCPLegalMatrix;
239 
241  /* Warning: using QList is slow on access */
243 
245  /* Warning: using QList is slow on access */
247 
250 
252  int mCPCols;
254  int mCPRows;
255 
258 
260  double mMaxSrcXRes;
261  double mMaxSrcYRes;
262 
265 };
266 
267 #endif
268