QGIS API Documentation  2.9.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:
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 override;
83 
84  int bandCount() const override;
85 
86  QGis::DataType dataType( int bandNo ) const override;
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 ) override;
105 
108  bool destExtentSize( const QgsRectangle& theSrcExtent, int theSrcXSize, int theSrcYSize,
109  QgsRectangle& theDestExtent, int& theDestXSize, int& theDesYSize );
110 
111  private:
113  QgsRectangle srcExtent() { return mSrcExtent; }
114 
116  int srcRows() { return mSrcRows; }
117  int srcCols() { return mSrcCols; }
118  void setSrcRows( int theRows ) { mSrcRows = theRows; mSrcXRes = mSrcExtent.height() / mSrcRows; }
119  void setSrcCols( int theCols ) { mSrcCols = theCols; mSrcYRes = mSrcExtent.width() / mSrcCols; }
120 
125  bool srcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol, const QgsCoordinateTransform* ct );
126 
127  int dstRows() const { return mDestRows; }
128  int dstCols() const { return mDestCols; }
129 
131  void destPointOnCPMatrix( int theRow, int theCol, double *theX, double *theY );
132 
134  int matrixRow( int theDestRow );
135  int matrixCol( int theDestCol );
136 
138  QgsPoint srcPoint( int theRow, int theCol );
139 
141  inline bool preciseSrcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol, const QgsCoordinateTransform* ct );
142 
144  inline bool approximateSrcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol );
145 
147  void calc();
148 
150  void insertRows( const QgsCoordinateTransform* ct );
151 
153  void insertCols( const QgsCoordinateTransform* ct );
154 
156  void calcCP( int theRow, int theCol, const QgsCoordinateTransform* ct );
157 
159  bool calcRow( int theRow, const QgsCoordinateTransform* ct );
160 
162  bool calcCol( int theCol, const QgsCoordinateTransform* ct );
163 
165  void calcSrcExtent();
166 
168  void calcSrcRowsCols();
169 
172  bool checkCols( const QgsCoordinateTransform* ct );
173 
176  bool checkRows( const QgsCoordinateTransform* ct );
177 
179  void calcHelper( int theMatrixRow, QgsPoint *thePoints );
180 
182  void nextHelper();
183 
185  QString cpToString();
186 
189 
192 
194  int mSrcDatumTransform;
195 
197  int mDestDatumTransform;
198 
200  QgsRectangle mDestExtent;
201 
203  QgsRectangle mSrcExtent;
204 
206  QgsRectangle mExtent;
207 
209  int mDestRows;
210 
212  int mDestCols;
213 
215  double mDestXRes;
216 
218  double mDestYRes;
219 
221  int mSrcRows;
222 
224  int mSrcCols;
225 
227  double mSrcXRes;
228 
230  double mSrcYRes;
231 
233  double mDestRowsPerMatrixRow;
234 
236  double mDestColsPerMatrixCol;
237 
239  QList< QList<QgsPoint> > mCPMatrix;
240 
242  /* Same size as mCPMatrix */
243  QList< QList<bool> > mCPLegalMatrix;
244 
246  /* Warning: using QList is slow on access */
247  QgsPoint *pHelperTop;
248 
250  /* Warning: using QList is slow on access */
251  QgsPoint *pHelperBottom;
252 
254  int mHelperTopRow;
255 
257  int mCPCols;
259  int mCPRows;
260 
262  double mSqrTolerance;
263 
265  double mMaxSrcXRes;
266  double mMaxSrcYRes;
267 
269  bool mApproximate;
270 };
271 
272 #endif
273 
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
Raster data container.
DataType
Raster data types.
Definition: qgis.h:204
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
QgsCoordinateReferenceSystem srcCrs() const
Get source CRS.
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:207