QGIS API Documentation  2.99.0-Master (cd0ba91)
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 QgsPointXY;
39 
47 class CORE_EXPORT QgsRasterProjector : public QgsRasterInterface
48 {
49  public:
50 
55  enum Precision
56  {
57  Approximate = 0,
58  Exact = 1,
59  };
60 
62 
63  QgsRasterProjector *clone() const override SIP_FACTORY;
64 
65  int bandCount() const override;
66 
67  Qgis::DataType dataType( int bandNo ) const override;
68 
70  void setCrs( const QgsCoordinateReferenceSystem &srcCRS, const QgsCoordinateReferenceSystem &destCRS,
71  int srcDatumTransform = -1, int destDatumTransform = -1 );
72 
74  QgsCoordinateReferenceSystem sourceCrs() const { return mSrcCRS; }
75 
77  QgsCoordinateReferenceSystem destinationCrs() const { return mDestCRS; }
78 
79  Precision precision() const { return mPrecision; }
80  void setPrecision( Precision precision ) { mPrecision = precision; }
81  // Translated precision mode, for use in ComboBox etc.
82  static QString precisionLabel( Precision precision );
83 
84  QgsRasterBlock *block( int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback = nullptr ) override SIP_FACTORY;
85 
87  bool destExtentSize( const QgsRectangle &srcExtent, int srcXSize, int srcYSize,
88  QgsRectangle &destExtent SIP_OUT, int &destXSize SIP_OUT, int &destYSize SIP_OUT );
89 
91  static bool extentSize( const QgsCoordinateTransform &ct,
92  const QgsRectangle &srcExtent, int srcXSize, int srcYSize,
93  QgsRectangle &destExtent SIP_OUT, int &destXSize SIP_OUT, int &destYSize SIP_OUT );
94 
95  private:
96 
99 
102 
104  int mSrcDatumTransform = -1;
105 
107  int mDestDatumTransform = -1;
108 
110  Precision mPrecision = Approximate;
111 
112 };
113 
114 
115 #ifndef SIP_RUN
116 
123 class ProjectorData
124 {
125  public:
127  ProjectorData( const QgsRectangle &extent, int width, int height, QgsRasterInterface *input, const QgsCoordinateTransform &inverseCt, QgsRasterProjector::Precision precision );
128  ~ProjectorData();
129 
130  ProjectorData( const ProjectorData &other ) = delete;
131  ProjectorData &operator=( const ProjectorData &other ) = delete;
132 
138  bool srcRowCol( int destRow, int destCol, int *srcRow, int *srcCol );
139 
140  QgsRectangle srcExtent() const { return mSrcExtent; }
141  int srcRows() const { return mSrcRows; }
142  int srcCols() const { return mSrcCols; }
143 
144  private:
145 
147  void destPointOnCPMatrix( int row, int col, double *theX, double *theY );
148 
150  int matrixRow( int destRow );
151  int matrixCol( int destCol );
152 
154  inline bool preciseSrcRowCol( int destRow, int destCol, int *srcRow, int *srcCol );
155 
157  inline bool approximateSrcRowCol( int destRow, int destCol, int *srcRow, int *srcCol );
158 
160  void insertRows( const QgsCoordinateTransform &ct );
161 
163  void insertCols( const QgsCoordinateTransform &ct );
164 
166  void calcCP( int row, int col, const QgsCoordinateTransform &ct );
167 
169  bool calcRow( int row, const QgsCoordinateTransform &ct );
170 
172  bool calcCol( int col, const QgsCoordinateTransform &ct );
173 
175  void calcSrcExtent();
176 
178  void calcSrcRowsCols();
179 
183  bool checkCols( const QgsCoordinateTransform &ct );
184 
188  bool checkRows( const QgsCoordinateTransform &ct );
189 
191  void calcHelper( int matrixRow, QgsPointXY *points );
192 
194  void nextHelper();
195 
197  QString cpToString();
198 
202  bool mApproximate;
203 
205  QgsCoordinateTransform mInverseCt;
206 
208  QgsRectangle mDestExtent;
209 
211  QgsRectangle mSrcExtent;
212 
214  QgsRectangle mExtent;
215 
217  int mDestRows;
218 
220  int mDestCols;
221 
223  double mDestXRes;
224 
226  double mDestYRes;
227 
229  int mSrcRows;
230 
232  int mSrcCols;
233 
235  double mSrcXRes;
236 
238  double mSrcYRes;
239 
241  double mDestRowsPerMatrixRow;
242 
244  double mDestColsPerMatrixCol;
245 
247  QList< QList<QgsPointXY> > mCPMatrix;
248 
250  /* Same size as mCPMatrix */
251  QList< QList<bool> > mCPLegalMatrix;
252 
254  /* Warning: using QList is slow on access */
255  QgsPointXY *pHelperTop = nullptr;
256 
258  /* Warning: using QList is slow on access */
259  QgsPointXY *pHelperBottom = nullptr;
260 
262  int mHelperTopRow;
263 
265  int mCPCols;
267  int mCPRows;
268 
270  double mSqrTolerance;
271 
273  double mMaxSrcXRes;
274  double mMaxSrcYRes;
275 
276 };
277 
279 #endif
280 
281 #endif
282 
A rectangle specified with double values.
Definition: qgsrectangle.h:39
Precision precision() const
A class to represent a 2D point.
Definition: qgspointxy.h:43
The Qgis class provides global constants for use throughout the application.
Definition: qgis.h:57
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:69
Base class for processing filters like renderers, reprojector, resampler etc.
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.
#define SIP_OUT
Definition: qgis_sip.h:51
This class represents a coordinate reference system (CRS).
Class for doing transforms between two map coordinate systems.
Feedback object tailored for raster block reading.