QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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  Q_GADGET
50 
51  public:
52 
57  enum Precision
58  {
59  Approximate = 0,
60  Exact = 1,
61  };
62  Q_ENUM( Precision )
63 
65 
66  QgsRasterProjector *clone() const override SIP_FACTORY;
67 
68  int bandCount() const override;
69 
70  Qgis::DataType dataType( int bandNo ) const override;
71 
76  Q_DECL_DEPRECATED void setCrs( const QgsCoordinateReferenceSystem &srcCRS, const QgsCoordinateReferenceSystem &destCRS,
77  int srcDatumTransform = -1, int destDatumTransform = -1 ) SIP_DEPRECATED;
78 
83  void setCrs( const QgsCoordinateReferenceSystem &srcCRS, const QgsCoordinateReferenceSystem &destCRS,
84  QgsCoordinateTransformContext transformContext );
85 
87  QgsCoordinateReferenceSystem sourceCrs() const { return mSrcCRS; }
88 
90  QgsCoordinateReferenceSystem destinationCrs() const { return mDestCRS; }
91 
92  Precision precision() const { return mPrecision; }
93  void setPrecision( Precision precision ) { mPrecision = precision; }
94  // Translated precision mode, for use in ComboBox etc.
95  static QString precisionLabel( Precision precision );
96 
97  QgsRasterBlock *block( int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback = nullptr ) override SIP_FACTORY;
98 
100  bool destExtentSize( const QgsRectangle &srcExtent, int srcXSize, int srcYSize,
101  QgsRectangle &destExtent SIP_OUT, int &destXSize SIP_OUT, int &destYSize SIP_OUT );
102 
104  static bool extentSize( const QgsCoordinateTransform &ct,
105  const QgsRectangle &srcExtent, int srcXSize, int srcYSize,
106  QgsRectangle &destExtent SIP_OUT, int &destXSize SIP_OUT, int &destYSize SIP_OUT );
107 
108  private:
109 
112 
115 
117  Q_DECL_DEPRECATED int mSrcDatumTransform = -1;
118 
120  Q_DECL_DEPRECATED int mDestDatumTransform = -1;
121 
123  Precision mPrecision = Approximate;
124 
125  QgsCoordinateTransformContext mTransformContext;
126 
127 };
128 
129 
130 #ifndef SIP_RUN
131 
138 class ProjectorData
139 {
140  public:
142  ProjectorData( const QgsRectangle &extent, int width, int height, QgsRasterInterface *input, const QgsCoordinateTransform &inverseCt, QgsRasterProjector::Precision precision );
143  ~ProjectorData();
144 
145  ProjectorData( const ProjectorData &other ) = delete;
146  ProjectorData &operator=( const ProjectorData &other ) = delete;
147 
153  bool srcRowCol( int destRow, int destCol, int *srcRow, int *srcCol );
154 
155  QgsRectangle srcExtent() const { return mSrcExtent; }
156  int srcRows() const { return mSrcRows; }
157  int srcCols() const { return mSrcCols; }
158 
159  private:
160 
162  void destPointOnCPMatrix( int row, int col, double *theX, double *theY );
163 
165  int matrixRow( int destRow );
166 
168  int matrixCol( int destCol );
169 
171  inline bool preciseSrcRowCol( int destRow, int destCol, int *srcRow, int *srcCol );
172 
174  inline bool approximateSrcRowCol( int destRow, int destCol, int *srcRow, int *srcCol );
175 
177  void insertRows( const QgsCoordinateTransform &ct );
178 
180  void insertCols( const QgsCoordinateTransform &ct );
181 
183  void calcCP( int row, int col, const QgsCoordinateTransform &ct );
184 
186  bool calcRow( int row, const QgsCoordinateTransform &ct );
187 
189  bool calcCol( int col, const QgsCoordinateTransform &ct );
190 
192  void calcSrcExtent();
193 
195  void calcSrcRowsCols();
196 
200  bool checkCols( const QgsCoordinateTransform &ct );
201 
205  bool checkRows( const QgsCoordinateTransform &ct );
206 
208  void calcHelper( int matrixRow, QgsPointXY *points );
209 
211  void nextHelper();
212 
214  QString cpToString();
215 
219  bool mApproximate;
220 
222  QgsCoordinateTransform mInverseCt;
223 
225  QgsRectangle mDestExtent;
226 
228  QgsRectangle mSrcExtent;
229 
231  QgsRectangle mExtent;
232 
234  int mDestRows;
235 
237  int mDestCols;
238 
240  double mDestXRes;
241 
243  double mDestYRes;
244 
246  int mSrcRows;
247 
249  int mSrcCols;
250 
252  double mSrcXRes;
253 
255  double mSrcYRes;
256 
258  double mDestRowsPerMatrixRow;
259 
261  double mDestColsPerMatrixCol;
262 
264  QList< QList<QgsPointXY> > mCPMatrix;
265 
267  /* Same size as mCPMatrix */
268  QList< QList<bool> > mCPLegalMatrix;
269 
271  /* Warning: using QList is slow on access */
272  QgsPointXY *pHelperTop = nullptr;
273 
275  /* Warning: using QList is slow on access */
276  QgsPointXY *pHelperBottom = nullptr;
277 
279  int mHelperTopRow;
280 
282  int mCPCols;
284  int mCPRows;
285 
287  double mSqrTolerance;
288 
290  double mMaxSrcXRes;
291  double mMaxSrcYRes;
292 
293 };
294 
296 #endif
297 
298 #endif
299 
int precision
A rectangle specified with double values.
Definition: qgsrectangle.h:41
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:45
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:76
Contains information about the context in which a coordinate transform is executed.
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
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
Returns the 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:58
This class represents a coordinate reference system (CRS).
Class for doing transforms between two map coordinate systems.
Feedback object tailored for raster block reading.