QGIS API Documentation  2.13.0-Master
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  QgsRasterProjector *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;
107  mMaxSrcYRes = theMaxSrcYRes;
108  }
109 
110  Precision precision() const { return mPrecision; }
111  void setPrecision( Precision precision ) { mPrecision = precision; }
112  // Translated precision mode, for use in ComboBox etc.
113  static QString precisionLabel( Precision precision );
114 
115  QgsRasterBlock *block( int bandNo, const QgsRectangle & extent, int width, int height ) override;
116 
118  bool destExtentSize( const QgsRectangle& theSrcExtent, int theSrcXSize, int theSrcYSize,
119  QgsRectangle& theDestExtent, int& theDestXSize, int& theDestYSize );
120 
122  static bool extentSize( const QgsCoordinateTransform* ct,
123  const QgsRectangle& theSrcExtent, int theSrcXSize, int theSrcYSize,
124  QgsRectangle& theDestExtent, int& theDestXSize, int& theDestYSize );
125 
126  private:
128  QgsRectangle srcExtent() { return mSrcExtent; }
129 
131  int srcRows() { return mSrcRows; }
132  int srcCols() { return mSrcCols; }
133  void setSrcRows( int theRows ) { mSrcRows = theRows; mSrcXRes = mSrcExtent.height() / mSrcRows; }
134  void setSrcCols( int theCols ) { mSrcCols = theCols; mSrcYRes = mSrcExtent.width() / mSrcCols; }
135 
140  bool srcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol, const QgsCoordinateTransform* ct );
141 
142  int dstRows() const { return mDestRows; }
143  int dstCols() const { return mDestCols; }
144 
146  void destPointOnCPMatrix( int theRow, int theCol, double *theX, double *theY );
147 
149  int matrixRow( int theDestRow );
150  int matrixCol( int theDestCol );
151 
153  QgsPoint srcPoint( int theRow, int theCol );
154 
156  inline bool preciseSrcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol, const QgsCoordinateTransform* ct );
157 
159  inline bool approximateSrcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol );
160 
162  void calc();
163 
165  void insertRows( const QgsCoordinateTransform* ct );
166 
168  void insertCols( const QgsCoordinateTransform* ct );
169 
171  void calcCP( int theRow, int theCol, const QgsCoordinateTransform* ct );
172 
174  bool calcRow( int theRow, const QgsCoordinateTransform* ct );
175 
177  bool calcCol( int theCol, const QgsCoordinateTransform* ct );
178 
180  void calcSrcExtent();
181 
183  void calcSrcRowsCols();
184 
187  bool checkCols( const QgsCoordinateTransform* ct );
188 
191  bool checkRows( const QgsCoordinateTransform* ct );
192 
194  void calcHelper( int theMatrixRow, QgsPoint *thePoints );
195 
197  void nextHelper();
198 
200  QString cpToString();
201 
204 
207 
209  int mSrcDatumTransform;
210 
212  int mDestDatumTransform;
213 
215  QgsRectangle mDestExtent;
216 
218  QgsRectangle mSrcExtent;
219 
221  QgsRectangle mExtent;
222 
224  int mDestRows;
225 
227  int mDestCols;
228 
230  double mDestXRes;
231 
233  double mDestYRes;
234 
236  int mSrcRows;
237 
239  int mSrcCols;
240 
242  double mSrcXRes;
243 
245  double mSrcYRes;
246 
248  double mDestRowsPerMatrixRow;
249 
251  double mDestColsPerMatrixCol;
252 
254  QList< QList<QgsPoint> > mCPMatrix;
255 
257  /* Same size as mCPMatrix */
258  QList< QList<bool> > mCPLegalMatrix;
259 
261  /* Warning: using QList is slow on access */
262  QgsPoint *pHelperTop;
263 
265  /* Warning: using QList is slow on access */
266  QgsPoint *pHelperBottom;
267 
269  int mHelperTopRow;
270 
272  int mCPCols;
274  int mCPRows;
275 
277  double mSqrTolerance;
278 
280  double mMaxSrcXRes;
281  double mMaxSrcYRes;
282 
284  Precision mPrecision;
285 
288  bool mApproximate;
289 };
290 
291 #endif
292 
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:129
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:65
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