QGIS API Documentation  2.11.0-Master
 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:
43  enum Precision
44  {
45  Approximate = 0,
46  Exact = 1,
47  };
48 
57  int theSrcDatumTransform,
58  int theDestDatumTransform,
59  QgsRectangle theDestExtent,
60  int theDestRows, int theDestCols,
61  double theMaxSrcXRes, double theMaxSrcYRes,
62  QgsRectangle theExtent
63  );
64 
68  QgsRectangle theDestExtent,
69  int theDestRows, int theDestCols,
70  double theMaxSrcXRes, double theMaxSrcYRes,
71  QgsRectangle theExtent
72  );
76  double theMaxSrcXRes, double theMaxSrcYRes,
77  QgsRectangle theExtent
78  );
81  // To avoid synthesized which fails on copy of QgsCoordinateTransform
82  // (QObject child) in Python bindings
83  QgsRasterProjector( const QgsRasterProjector &projector );
84 
87 
88  QgsRasterProjector & operator=( const QgsRasterProjector &projector );
89 
90  QgsRasterInterface *clone() const override;
91 
92  int bandCount() const override;
93 
94  QGis::DataType dataType( int bandNo ) const override;
95 
97  void setCRS( const QgsCoordinateReferenceSystem & theSrcCRS, const QgsCoordinateReferenceSystem & theDestCRS,
98  int srcDatumTransform = -1, int destDatumTransform = -1 );
99 
101  QgsCoordinateReferenceSystem srcCrs() const { return mSrcCRS; }
102 
104  QgsCoordinateReferenceSystem destCrs() const { return mDestCRS; }
105 
107  void setMaxSrcRes( double theMaxSrcXRes, double theMaxSrcYRes )
108  {
109  mMaxSrcXRes = theMaxSrcXRes; mMaxSrcYRes = theMaxSrcYRes;
110  }
111 
112  Precision precision() const { return mPrecision; }
113  void setPrecision( Precision precision ) { mPrecision = precision; }
114  // Translated precision mode, for use in ComboBox etc.
115  static QString precisionLabel( Precision precision );
116 
117  QgsRasterBlock *block( int bandNo, const QgsRectangle & extent, int width, int height ) override;
118 
120  bool destExtentSize( const QgsRectangle& theSrcExtent, int theSrcXSize, int theSrcYSize,
121  QgsRectangle& theDestExtent, int& theDestXSize, int& theDestYSize );
122 
124  static bool extentSize( const QgsCoordinateTransform* ct,
125  const QgsRectangle& theSrcExtent, int theSrcXSize, int theSrcYSize,
126  QgsRectangle& theDestExtent, int& theDestXSize, int& theDestYSize );
127 
128  private:
130  QgsRectangle srcExtent() { return mSrcExtent; }
131 
133  int srcRows() { return mSrcRows; }
134  int srcCols() { return mSrcCols; }
135  void setSrcRows( int theRows ) { mSrcRows = theRows; mSrcXRes = mSrcExtent.height() / mSrcRows; }
136  void setSrcCols( int theCols ) { mSrcCols = theCols; mSrcYRes = mSrcExtent.width() / mSrcCols; }
137 
142  bool srcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol, const QgsCoordinateTransform* ct );
143 
144  int dstRows() const { return mDestRows; }
145  int dstCols() const { return mDestCols; }
146 
148  void destPointOnCPMatrix( int theRow, int theCol, double *theX, double *theY );
149 
151  int matrixRow( int theDestRow );
152  int matrixCol( int theDestCol );
153 
155  QgsPoint srcPoint( int theRow, int theCol );
156 
158  inline bool preciseSrcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol, const QgsCoordinateTransform* ct );
159 
161  inline bool approximateSrcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol );
162 
164  void calc();
165 
167  void insertRows( const QgsCoordinateTransform* ct );
168 
170  void insertCols( const QgsCoordinateTransform* ct );
171 
173  void calcCP( int theRow, int theCol, const QgsCoordinateTransform* ct );
174 
176  bool calcRow( int theRow, const QgsCoordinateTransform* ct );
177 
179  bool calcCol( int theCol, const QgsCoordinateTransform* ct );
180 
182  void calcSrcExtent();
183 
185  void calcSrcRowsCols();
186 
189  bool checkCols( const QgsCoordinateTransform* ct );
190 
193  bool checkRows( const QgsCoordinateTransform* ct );
194 
196  void calcHelper( int theMatrixRow, QgsPoint *thePoints );
197 
199  void nextHelper();
200 
202  QString cpToString();
203 
206 
209 
211  int mSrcDatumTransform;
212 
214  int mDestDatumTransform;
215 
217  QgsRectangle mDestExtent;
218 
220  QgsRectangle mSrcExtent;
221 
223  QgsRectangle mExtent;
224 
226  int mDestRows;
227 
229  int mDestCols;
230 
232  double mDestXRes;
233 
235  double mDestYRes;
236 
238  int mSrcRows;
239 
241  int mSrcCols;
242 
244  double mSrcXRes;
245 
247  double mSrcYRes;
248 
250  double mDestRowsPerMatrixRow;
251 
253  double mDestColsPerMatrixCol;
254 
256  QList< QList<QgsPoint> > mCPMatrix;
257 
259  /* Same size as mCPMatrix */
260  QList< QList<bool> > mCPLegalMatrix;
261 
263  /* Warning: using QList is slow on access */
264  QgsPoint *pHelperTop;
265 
267  /* Warning: using QList is slow on access */
268  QgsPoint *pHelperBottom;
269 
271  int mHelperTopRow;
272 
274  int mCPCols;
276  int mCPRows;
277 
279  double mSqrTolerance;
280 
282  double mMaxSrcXRes;
283  double mMaxSrcYRes;
284 
286  Precision mPrecision;
287 
290  bool mApproximate;
291 };
292 
293 #endif
294 
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:63
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:204
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:207