QGIS API Documentation  2.99.0-Master (13a3f2f)
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 "qgis_sip.h"
28 #include <QVector>
29 #include <QList>
30 
31 #include "qgsrectangle.h"
33 #include "qgscoordinatetransform.h"
34 #include "qgsrasterinterface.h"
35 
36 #include <cmath>
37 
38 class QgsPoint;
39 
46 class CORE_EXPORT QgsRasterProjector : public QgsRasterInterface
47 {
48  public:
49 
53  enum Precision
54  {
55  Approximate = 0,
56  Exact = 1,
57  };
58 
60 
61  QgsRasterProjector *clone() const override SIP_FACTORY;
62 
63  int bandCount() const override;
64 
65  Qgis::DataType dataType( int bandNo ) const override;
66 
68  void setCrs( const QgsCoordinateReferenceSystem &srcCRS, const QgsCoordinateReferenceSystem &destCRS,
69  int srcDatumTransform = -1, int destDatumTransform = -1 );
70 
72  QgsCoordinateReferenceSystem sourceCrs() const { return mSrcCRS; }
73 
75  QgsCoordinateReferenceSystem destinationCrs() const { return mDestCRS; }
76 
77  Precision precision() const { return mPrecision; }
78  void setPrecision( Precision precision ) { mPrecision = precision; }
79  // Translated precision mode, for use in ComboBox etc.
80  static QString precisionLabel( Precision precision );
81 
82  QgsRasterBlock *block( int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback = nullptr ) override;
83 
85  bool destExtentSize( const QgsRectangle &srcExtent, int srcXSize, int srcYSize,
86  QgsRectangle &destExtent, int &destXSize, int &destYSize );
87 
89  static bool extentSize( const QgsCoordinateTransform &ct,
90  const QgsRectangle &srcExtent, int srcXSize, int srcYSize,
91  QgsRectangle &destExtent, int &destXSize, int &destYSize );
92 
93  private:
94 
97 
100 
102  int mSrcDatumTransform;
103 
105  int mDestDatumTransform;
106 
108  Precision mPrecision;
109 
110 };
111 
113 
119 class ProjectorData
120 {
121  public:
123  ProjectorData( const QgsRectangle &extent, int width, int height, QgsRasterInterface *input, const QgsCoordinateTransform &inverseCt, QgsRasterProjector::Precision precision );
124  ~ProjectorData();
125 
126  ProjectorData( const ProjectorData &other ) = delete;
127  ProjectorData &operator=( const ProjectorData &other ) = delete;
128 
133  bool srcRowCol( int destRow, int destCol, int *srcRow, int *srcCol );
134 
135  QgsRectangle srcExtent() const { return mSrcExtent; }
136  int srcRows() const { return mSrcRows; }
137  int srcCols() const { return mSrcCols; }
138 
139  private:
140 
142  void destPointOnCPMatrix( int row, int col, double *theX, double *theY );
143 
145  int matrixRow( int destRow );
146  int matrixCol( int destCol );
147 
149  inline bool preciseSrcRowCol( int destRow, int destCol, int *srcRow, int *srcCol );
150 
152  inline bool approximateSrcRowCol( int destRow, int destCol, int *srcRow, int *srcCol );
153 
155  void insertRows( const QgsCoordinateTransform &ct );
156 
158  void insertCols( const QgsCoordinateTransform &ct );
159 
161  void calcCP( int row, int col, const QgsCoordinateTransform &ct );
162 
164  bool calcRow( int row, const QgsCoordinateTransform &ct );
165 
167  bool calcCol( int col, 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 matrixRow, QgsPoint *points );
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 = nullptr;
248 
250  /* Warning: using QList is slow on access */
251  QgsPoint *pHelperBottom = nullptr;
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 
A rectangle specified with double values.
Definition: qgsrectangle.h:38
Precision precision() const
The Qgis class provides global constants for use throughout the application.
Definition: qgis.h:44
Raster data container.
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.
#define SIP_FACTORY
Definition: qgis_sip.h:57
Base class for processing filters like renderers, reprojector, resampler etc.
A class to represent a point.
Definition: qgspoint.h:37
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.