QGIS API Documentation  2.12.0-Lyon
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 
55  const QgsCoordinateReferenceSystem& theDestCRS,
56  int theSrcDatumTransform,
57  int theDestDatumTransform,
58  const QgsRectangle& theDestExtent,
59  int theDestRows, int theDestCols,
60  double theMaxSrcXRes, double theMaxSrcYRes,
61  const QgsRectangle& theExtent
62  );
63 
65  const QgsCoordinateReferenceSystem& theDestCRS,
66  const QgsRectangle& theDestExtent,
67  int theDestRows, int theDestCols,
68  double theMaxSrcXRes, double theMaxSrcYRes,
69  const QgsRectangle& theExtent
70  );
72  const QgsCoordinateReferenceSystem& theDestCRS,
73  double theMaxSrcXRes, double theMaxSrcYRes,
74  const QgsRectangle& theExtent
75  );
78  // To avoid synthesized which fails on copy of QgsCoordinateTransform
79  // (QObject child) in Python bindings
80  QgsRasterProjector( const QgsRasterProjector &projector );
81 
84 
85  QgsRasterProjector & operator=( const QgsRasterProjector &projector );
86 
87  QgsRasterInterface *clone() const override;
88 
89  int bandCount() const override;
90 
91  QGis::DataType dataType( int bandNo ) const override;
92 
94  void setCRS( const QgsCoordinateReferenceSystem & theSrcCRS, const QgsCoordinateReferenceSystem & theDestCRS,
95  int srcDatumTransform = -1, int destDatumTransform = -1 );
96 
98  QgsCoordinateReferenceSystem srcCrs() const { return mSrcCRS; }
99 
101  QgsCoordinateReferenceSystem destCrs() const { return mDestCRS; }
102 
104  void setMaxSrcRes( double theMaxSrcXRes, double theMaxSrcYRes )
105  {
106  mMaxSrcXRes = theMaxSrcXRes; mMaxSrcYRes = theMaxSrcYRes;
107  }
108 
109  Precision precision() const { return mPrecision; }
110  void setPrecision( Precision precision ) { mPrecision = precision; }
111  // Translated precision mode, for use in ComboBox etc.
112  static QString precisionLabel( Precision precision );
113 
114  QgsRasterBlock *block( int bandNo, const QgsRectangle & extent, int width, int height ) override;
115 
117  bool destExtentSize( const QgsRectangle& theSrcExtent, int theSrcXSize, int theSrcYSize,
118  QgsRectangle& theDestExtent, int& theDestXSize, int& theDestYSize );
119 
121  static bool extentSize( const QgsCoordinateTransform* ct,
122  const QgsRectangle& theSrcExtent, int theSrcXSize, int theSrcYSize,
123  QgsRectangle& theDestExtent, int& theDestXSize, int& theDestYSize );
124 
125  private:
127  QgsRectangle srcExtent() { return mSrcExtent; }
128 
130  int srcRows() { return mSrcRows; }
131  int srcCols() { return mSrcCols; }
132  void setSrcRows( int theRows ) { mSrcRows = theRows; mSrcXRes = mSrcExtent.height() / mSrcRows; }
133  void setSrcCols( int theCols ) { mSrcCols = theCols; mSrcYRes = mSrcExtent.width() / mSrcCols; }
134 
139  bool srcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol, const QgsCoordinateTransform* ct );
140 
141  int dstRows() const { return mDestRows; }
142  int dstCols() const { return mDestCols; }
143 
145  void destPointOnCPMatrix( int theRow, int theCol, double *theX, double *theY );
146 
148  int matrixRow( int theDestRow );
149  int matrixCol( int theDestCol );
150 
152  QgsPoint srcPoint( int theRow, int theCol );
153 
155  inline bool preciseSrcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol, const QgsCoordinateTransform* ct );
156 
158  inline bool approximateSrcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol );
159 
161  void calc();
162 
164  void insertRows( const QgsCoordinateTransform* ct );
165 
167  void insertCols( const QgsCoordinateTransform* ct );
168 
170  void calcCP( int theRow, int theCol, const QgsCoordinateTransform* ct );
171 
173  bool calcRow( int theRow, const QgsCoordinateTransform* ct );
174 
176  bool calcCol( int theCol, const QgsCoordinateTransform* ct );
177 
179  void calcSrcExtent();
180 
182  void calcSrcRowsCols();
183 
186  bool checkCols( const QgsCoordinateTransform* ct );
187 
190  bool checkRows( const QgsCoordinateTransform* ct );
191 
193  void calcHelper( int theMatrixRow, QgsPoint *thePoints );
194 
196  void nextHelper();
197 
199  QString cpToString();
200 
203 
206 
208  int mSrcDatumTransform;
209 
211  int mDestDatumTransform;
212 
214  QgsRectangle mDestExtent;
215 
217  QgsRectangle mSrcExtent;
218 
220  QgsRectangle mExtent;
221 
223  int mDestRows;
224 
226  int mDestCols;
227 
229  double mDestXRes;
230 
232  double mDestYRes;
233 
235  int mSrcRows;
236 
238  int mSrcCols;
239 
241  double mSrcXRes;
242 
244  double mSrcYRes;
245 
247  double mDestRowsPerMatrixRow;
248 
250  double mDestColsPerMatrixCol;
251 
253  QList< QList<QgsPoint> > mCPMatrix;
254 
256  /* Same size as mCPMatrix */
257  QList< QList<bool> > mCPLegalMatrix;
258 
260  /* Warning: using QList is slow on access */
261  QgsPoint *pHelperTop;
262 
264  /* Warning: using QList is slow on access */
265  QgsPoint *pHelperBottom;
266 
268  int mHelperTopRow;
269 
271  int mCPCols;
273  int mCPRows;
274 
276  double mSqrTolerance;
277 
279  double mMaxSrcXRes;
280  double mMaxSrcYRes;
281 
283  Precision mPrecision;
284 
287  bool mApproximate;
288 };
289 
290 #endif
291 
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.
DataType
Raster data types.
Definition: qgis.h:122
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)
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:211