QGIS API Documentation  2.17.0-Master (872e6d2)
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 
41 class CORE_EXPORT QgsRasterProjector : public QgsRasterInterface
42 {
43  public:
47  enum Precision
48  {
49  Approximate = 0,
50  Exact = 1,
51  };
52 
59  const QgsCoordinateReferenceSystem& theDestCRS,
60  int theSrcDatumTransform,
61  int theDestDatumTransform,
62  const QgsRectangle& theDestExtent,
63  int theDestRows, int theDestCols,
64  double theMaxSrcXRes, double theMaxSrcYRes,
65  const QgsRectangle& theExtent
66  );
67 
69  const QgsCoordinateReferenceSystem& theDestCRS,
70  const QgsRectangle& theDestExtent,
71  int theDestRows, int theDestCols,
72  double theMaxSrcXRes, double theMaxSrcYRes,
73  const QgsRectangle& theExtent
74  );
76  const QgsCoordinateReferenceSystem& theDestCRS,
77  double theMaxSrcXRes, double theMaxSrcYRes,
78  const QgsRectangle& theExtent
79  );
82  // To avoid synthesized which fails on copy of QgsCoordinateTransform
83  // (QObject child) in Python bindings
84  QgsRasterProjector( const QgsRasterProjector &projector );
85 
88 
89  QgsRasterProjector & operator=( const QgsRasterProjector &projector );
90 
91  QgsRasterProjector *clone() const override;
92 
93  int bandCount() const override;
94 
95  QGis::DataType dataType( int bandNo ) const override;
96 
98  void setCRS( const QgsCoordinateReferenceSystem & theSrcCRS, const QgsCoordinateReferenceSystem & theDestCRS,
99  int srcDatumTransform = -1, int destDatumTransform = -1 );
100 
102  QgsCoordinateReferenceSystem srcCrs() const { return mSrcCRS; }
103 
105  QgsCoordinateReferenceSystem destCrs() const { return mDestCRS; }
106 
108  void setMaxSrcRes( double theMaxSrcXRes, double theMaxSrcYRes )
109  {
110  mMaxSrcXRes = theMaxSrcXRes;
111  mMaxSrcYRes = theMaxSrcYRes;
112  }
113 
114  Precision precision() const { return mPrecision; }
115  void setPrecision( Precision precision ) { mPrecision = precision; }
116  // Translated precision mode, for use in ComboBox etc.
117  static QString precisionLabel( Precision precision );
118 
119  QgsRasterBlock *block( int bandNo, const QgsRectangle & extent, int width, int height ) override;
120 
122  bool destExtentSize( const QgsRectangle& theSrcExtent, int theSrcXSize, int theSrcYSize,
123  QgsRectangle& theDestExtent, int& theDestXSize, int& theDestYSize );
124 
126  static bool extentSize( const QgsCoordinateTransform* ct,
127  const QgsRectangle& theSrcExtent, int theSrcXSize, int theSrcYSize,
128  QgsRectangle& theDestExtent, int& theDestXSize, int& theDestYSize );
129 
130  private:
132  QgsRectangle srcExtent() { return mSrcExtent; }
133 
135  int srcRows() { return mSrcRows; }
136  int srcCols() { return mSrcCols; }
137  void setSrcRows( int theRows ) { mSrcRows = theRows; mSrcXRes = mSrcExtent.height() / mSrcRows; }
138  void setSrcCols( int theCols ) { mSrcCols = theCols; mSrcYRes = mSrcExtent.width() / mSrcCols; }
139 
144  bool srcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol, const QgsCoordinateTransform* ct );
145 
146  int dstRows() const { return mDestRows; }
147  int dstCols() const { return mDestCols; }
148 
150  void destPointOnCPMatrix( int theRow, int theCol, double *theX, double *theY );
151 
153  int matrixRow( int theDestRow );
154  int matrixCol( int theDestCol );
155 
157  QgsPoint srcPoint( int theRow, int theCol );
158 
160  inline bool preciseSrcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol, const QgsCoordinateTransform* ct );
161 
163  inline bool approximateSrcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol );
164 
166  void calc();
167 
169  void insertRows( const QgsCoordinateTransform* ct );
170 
172  void insertCols( const QgsCoordinateTransform* ct );
173 
175  void calcCP( int theRow, int theCol, const QgsCoordinateTransform* ct );
176 
178  bool calcRow( int theRow, const QgsCoordinateTransform* ct );
179 
181  bool calcCol( int theCol, const QgsCoordinateTransform* ct );
182 
184  void calcSrcExtent();
185 
187  void calcSrcRowsCols();
188 
191  bool checkCols( const QgsCoordinateTransform* ct );
192 
195  bool checkRows( const QgsCoordinateTransform* ct );
196 
198  void calcHelper( int theMatrixRow, QgsPoint *thePoints );
199 
201  void nextHelper();
202 
204  QString cpToString();
205 
208 
211 
213  int mSrcDatumTransform;
214 
216  int mDestDatumTransform;
217 
219  QgsRectangle mDestExtent;
220 
222  QgsRectangle mSrcExtent;
223 
225  QgsRectangle mExtent;
226 
228  int mDestRows;
229 
231  int mDestCols;
232 
234  double mDestXRes;
235 
237  double mDestYRes;
238 
240  int mSrcRows;
241 
243  int mSrcCols;
244 
246  double mSrcXRes;
247 
249  double mSrcYRes;
250 
252  double mDestRowsPerMatrixRow;
253 
255  double mDestColsPerMatrixCol;
256 
258  QList< QList<QgsPoint> > mCPMatrix;
259 
261  /* Same size as mCPMatrix */
262  QList< QList<bool> > mCPLegalMatrix;
263 
265  /* Warning: using QList is slow on access */
266  QgsPoint *pHelperTop;
267 
269  /* Warning: using QList is slow on access */
270  QgsPoint *pHelperBottom;
271 
273  int mHelperTopRow;
274 
276  int mCPCols;
278  int mCPRows;
279 
281  double mSqrTolerance;
282 
284  double mMaxSrcXRes;
285  double mMaxSrcYRes;
286 
288  Precision mPrecision;
289 
292  bool mApproximate;
293 };
294 
295 #endif
296 
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:117
void setPrecision(Precision precision)
QgsCoordinateReferenceSystem srcCrs() const
Get source CRS.
Precision
Precision defines if each pixel is reprojected or approximate reprojection based on an approximation ...
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:133
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