QGIS API Documentation  2.99.0-Master (6a61179)
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 "qgsrasterinterface.h"
32 
33 #include <cmath>
34 
35 class QgsPoint;
37 
44 class CORE_EXPORT QgsRasterProjector : public QgsRasterInterface
45 {
46  public:
47 
51  enum Precision
52  {
53  Approximate = 0,
54  Exact = 1,
55  };
56 
58 
61 
62  QgsRasterProjector *clone() const override;
63 
64  int bandCount() const override;
65 
66  Qgis::DataType dataType( int bandNo ) const override;
67 
69  void setCrs( const QgsCoordinateReferenceSystem & theSrcCRS, const QgsCoordinateReferenceSystem & theDestCRS,
70  int srcDatumTransform = -1, int destDatumTransform = -1 );
71 
73  QgsCoordinateReferenceSystem sourceCrs() const { return mSrcCRS; }
74 
76  QgsCoordinateReferenceSystem destinationCrs() const { return mDestCRS; }
77 
78  Precision precision() const { return mPrecision; }
79  void setPrecision( Precision precision ) { mPrecision = precision; }
80  // Translated precision mode, for use in ComboBox etc.
81  static QString precisionLabel( Precision precision );
82 
83  QgsRasterBlock *block( int bandNo, const QgsRectangle & extent, int width, int height, QgsRasterBlockFeedback* feedback = nullptr ) override;
84 
86  bool destExtentSize( const QgsRectangle& theSrcExtent, int theSrcXSize, int theSrcYSize,
87  QgsRectangle& theDestExtent, int& theDestXSize, int& theDestYSize );
88 
90  static bool extentSize( const QgsCoordinateTransform& ct,
91  const QgsRectangle& theSrcExtent, int theSrcXSize, int theSrcYSize,
92  QgsRectangle& theDestExtent, int& theDestXSize, int& theDestYSize );
93 
94  private:
95 
98 
101 
103  int mSrcDatumTransform;
104 
106  int mDestDatumTransform;
107 
109  Precision mPrecision;
110 
111 };
112 
114 
120 class ProjectorData
121 {
122  public:
124  ProjectorData( const QgsRectangle &extent, int width, int height, QgsRasterInterface *input, const QgsCoordinateTransform &inverseCt, QgsRasterProjector::Precision precision );
125  ~ProjectorData();
126 
131  bool srcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol );
132 
133  QgsRectangle srcExtent() const { return mSrcExtent; }
134  int srcRows() const { return mSrcRows; }
135  int srcCols() const { return mSrcCols; }
136 
137  private:
138  ProjectorData( const ProjectorData& other );
139  ProjectorData& operator=( const ProjectorData& other );
140 
142  void destPointOnCPMatrix( int theRow, int theCol, double *theX, double *theY );
143 
145  int matrixRow( int theDestRow );
146  int matrixCol( int theDestCol );
147 
149  inline bool preciseSrcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol );
150 
152  inline bool approximateSrcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol );
153 
155  void insertRows( const QgsCoordinateTransform& ct );
156 
158  void insertCols( const QgsCoordinateTransform& ct );
159 
161  void calcCP( int theRow, int theCol, const QgsCoordinateTransform& ct );
162 
164  bool calcRow( int theRow, const QgsCoordinateTransform& ct );
165 
167  bool calcCol( int theCol, const QgsCoordinateTransform& ct );
168 
170  void calcSrcExtent();
171 
173  void calcSrcRowsCols();
174 
177  bool checkCols( const QgsCoordinateTransform& ct );
178 
181  bool checkRows( const QgsCoordinateTransform& ct );
182 
184  void calcHelper( int theMatrixRow, QgsPoint *thePoints );
185 
187  void nextHelper();
188 
190  QString cpToString();
191 
194  bool mApproximate;
195 
197  QgsCoordinateTransform* mInverseCt;
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 
268 };
269 
271 
272 #endif
273 
virtual int bandCount() const =0
Get number of bands.
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Precision precision() const
DataType
Raster data types.
Definition: qgis.h:60
virtual Qgis::DataType dataType(int bandNo) const =0
Returns data type for the band specified by number.
Raster data container.
QgsCoordinateReferenceSystem sourceCrs() const
Get source CRS.
virtual QgsRasterBlock * block(int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback=nullptr)=0
Read block of data using given extent and size.
Base class for processing filters like renderers, reprojector, resampler etc.
A class to represent a point.
Definition: qgspoint.h:111
void setPrecision(Precision precision)
QgsRasterProjector implements approximate projection support for it calculates grid of points in sour...
QgsCoordinateReferenceSystem destinationCrs() const
Get destination 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.
This class represents a coordinate reference system (CRS).
Class for doing transforms between two map coordinate systems.
Feedback object tailored for raster block reading.