QGIS API Documentation  2.99.0-Master (9ed189e)
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 "qgis_core.h"
27 #include <QVector>
28 #include <QList>
29 
30 #include "qgsrectangle.h"
32 #include "qgsrasterinterface.h"
33 
34 #include <cmath>
35 
36 class QgsPoint;
38 
45 class CORE_EXPORT QgsRasterProjector : public QgsRasterInterface
46 {
47  public:
48 
52  enum Precision
53  {
54  Approximate = 0,
55  Exact = 1,
56  };
57 
59 
60  QgsRasterProjector *clone() const override;
61 
62  int bandCount() const override;
63 
64  Qgis::DataType dataType( int bandNo ) const override;
65 
67  void setCrs( const QgsCoordinateReferenceSystem & theSrcCRS, const QgsCoordinateReferenceSystem & theDestCRS,
68  int srcDatumTransform = -1, int destDatumTransform = -1 );
69 
71  QgsCoordinateReferenceSystem sourceCrs() const { return mSrcCRS; }
72 
74  QgsCoordinateReferenceSystem destinationCrs() const { return mDestCRS; }
75 
76  Precision precision() const { return mPrecision; }
77  void setPrecision( Precision precision ) { mPrecision = precision; }
78  // Translated precision mode, for use in ComboBox etc.
79  static QString precisionLabel( Precision precision );
80 
81  QgsRasterBlock *block( int bandNo, const QgsRectangle & extent, int width, int height, QgsRasterBlockFeedback* feedback = nullptr ) override;
82 
84  bool destExtentSize( const QgsRectangle& theSrcExtent, int theSrcXSize, int theSrcYSize,
85  QgsRectangle& theDestExtent, int& theDestXSize, int& theDestYSize );
86 
88  static bool extentSize( const QgsCoordinateTransform& ct,
89  const QgsRectangle& theSrcExtent, int theSrcXSize, int theSrcYSize,
90  QgsRectangle& theDestExtent, int& theDestXSize, int& theDestYSize );
91 
92  private:
93 
96 
99 
101  int mSrcDatumTransform;
102 
104  int mDestDatumTransform;
105 
107  Precision mPrecision;
108 
109 };
110 
112 
118 class ProjectorData
119 {
120  public:
122  ProjectorData( const QgsRectangle &extent, int width, int height, QgsRasterInterface *input, const QgsCoordinateTransform &inverseCt, QgsRasterProjector::Precision precision );
123  ~ProjectorData();
124 
125  ProjectorData( const ProjectorData& other ) = delete;
126  ProjectorData& operator=( const ProjectorData& other ) = delete;
127 
132  bool srcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol );
133 
134  QgsRectangle srcExtent() const { return mSrcExtent; }
135  int srcRows() const { return mSrcRows; }
136  int srcCols() const { return mSrcCols; }
137 
138  private:
139 
141  void destPointOnCPMatrix( int theRow, int theCol, double *theX, double *theY );
142 
144  int matrixRow( int theDestRow );
145  int matrixCol( int theDestCol );
146 
148  inline bool preciseSrcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol );
149 
151  inline bool approximateSrcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol );
152 
154  void insertRows( const QgsCoordinateTransform& ct );
155 
157  void insertCols( const QgsCoordinateTransform& ct );
158 
160  void calcCP( int theRow, int theCol, const QgsCoordinateTransform& ct );
161 
163  bool calcRow( int theRow, const QgsCoordinateTransform& ct );
164 
166  bool calcCol( int theCol, const QgsCoordinateTransform& ct );
167 
169  void calcSrcExtent();
170 
172  void calcSrcRowsCols();
173 
176  bool checkCols( const QgsCoordinateTransform& ct );
177 
180  bool checkRows( const QgsCoordinateTransform& ct );
181 
183  void calcHelper( int theMatrixRow, QgsPoint *thePoints );
184 
186  void nextHelper();
187 
189  QString cpToString();
190 
193  bool mApproximate;
194 
196  QgsCoordinateTransform* mInverseCt = nullptr;
197 
199  QgsRectangle mDestExtent;
200 
202  QgsRectangle mSrcExtent;
203 
205  QgsRectangle mExtent;
206 
208  int mDestRows;
209 
211  int mDestCols;
212 
214  double mDestXRes;
215 
217  double mDestYRes;
218 
220  int mSrcRows;
221 
223  int mSrcCols;
224 
226  double mSrcXRes;
227 
229  double mSrcYRes;
230 
232  double mDestRowsPerMatrixRow;
233 
235  double mDestColsPerMatrixCol;
236 
238  QList< QList<QgsPoint> > mCPMatrix;
239 
241  /* Same size as mCPMatrix */
242  QList< QList<bool> > mCPLegalMatrix;
243 
245  /* Warning: using QList is slow on access */
246  QgsPoint *pHelperTop = nullptr;
247 
249  /* Warning: using QList is slow on access */
250  QgsPoint *pHelperBottom = nullptr;
251 
253  int mHelperTopRow;
254 
256  int mCPCols;
258  int mCPRows;
259 
261  double mSqrTolerance;
262 
264  double mMaxSrcXRes;
265  double mMaxSrcYRes;
266 
267 };
268 
270 
271 #endif
272 
virtual int bandCount() const =0
Get number of bands.
A rectangle specified with double values.
Definition: qgsrectangle.h:36
Precision precision() const
DataType
Raster data types.
Definition: qgis.h:61
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:143
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.