QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 
73  void setCrs( const QgsCoordinateReferenceSystem &srcCRS, const QgsCoordinateReferenceSystem &destCRS,
74  int srcDatumTransform = -1, int destDatumTransform = -1 );
75 
77  QgsCoordinateReferenceSystem sourceCrs() const { return mSrcCRS; }
78 
80  QgsCoordinateReferenceSystem destinationCrs() const { return mDestCRS; }
81 
82  Precision precision() const { return mPrecision; }
83  void setPrecision( Precision precision ) { mPrecision = precision; }
84  // Translated precision mode, for use in ComboBox etc.
85  static QString precisionLabel( Precision precision );
86 
87  QgsRasterBlock *block( int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback = nullptr ) override SIP_FACTORY;
88 
90  bool destExtentSize( const QgsRectangle &srcExtent, int srcXSize, int srcYSize,
91  QgsRectangle &destExtent SIP_OUT, int &destXSize SIP_OUT, int &destYSize SIP_OUT );
92 
94  static bool extentSize( const QgsCoordinateTransform &ct,
95  const QgsRectangle &srcExtent, int srcXSize, int srcYSize,
96  QgsRectangle &destExtent SIP_OUT, int &destXSize SIP_OUT, int &destYSize SIP_OUT );
97 
98  private:
99 
102 
105 
107  int mSrcDatumTransform = -1;
108 
110  int mDestDatumTransform = -1;
111 
113  Precision mPrecision = Approximate;
114 
115 };
116 
117 
118 #ifndef SIP_RUN
119 
126 class ProjectorData
127 {
128  public:
130  ProjectorData( const QgsRectangle &extent, int width, int height, QgsRasterInterface *input, const QgsCoordinateTransform &inverseCt, QgsRasterProjector::Precision precision );
131  ~ProjectorData();
132 
133  ProjectorData( const ProjectorData &other ) = delete;
134  ProjectorData &operator=( const ProjectorData &other ) = delete;
135 
141  bool srcRowCol( int destRow, int destCol, int *srcRow, int *srcCol );
142 
143  QgsRectangle srcExtent() const { return mSrcExtent; }
144  int srcRows() const { return mSrcRows; }
145  int srcCols() const { return mSrcCols; }
146 
147  private:
148 
150  void destPointOnCPMatrix( int row, int col, double *theX, double *theY );
151 
153  int matrixRow( int destRow );
154 
156  int matrixCol( int destCol );
157 
159  inline bool preciseSrcRowCol( int destRow, int destCol, int *srcRow, int *srcCol );
160 
162  inline bool approximateSrcRowCol( int destRow, int destCol, int *srcRow, int *srcCol );
163 
165  void insertRows( const QgsCoordinateTransform &ct );
166 
168  void insertCols( const QgsCoordinateTransform &ct );
169 
171  void calcCP( int row, int col, const QgsCoordinateTransform &ct );
172 
174  bool calcRow( int row, const QgsCoordinateTransform &ct );
175 
177  bool calcCol( int col, const QgsCoordinateTransform &ct );
178 
180  void calcSrcExtent();
181 
183  void calcSrcRowsCols();
184 
188  bool checkCols( const QgsCoordinateTransform &ct );
189 
193  bool checkRows( const QgsCoordinateTransform &ct );
194 
196  void calcHelper( int matrixRow, QgsPointXY *points );
197 
199  void nextHelper();
200 
202  QString cpToString();
203 
207  bool mApproximate;
208 
210  QgsCoordinateTransform mInverseCt;
211 
213  QgsRectangle mDestExtent;
214 
216  QgsRectangle mSrcExtent;
217 
219  QgsRectangle mExtent;
220 
222  int mDestRows;
223 
225  int mDestCols;
226 
228  double mDestXRes;
229 
231  double mDestYRes;
232 
234  int mSrcRows;
235 
237  int mSrcCols;
238 
240  double mSrcXRes;
241 
243  double mSrcYRes;
244 
246  double mDestRowsPerMatrixRow;
247 
249  double mDestColsPerMatrixCol;
250 
252  QList< QList<QgsPointXY> > mCPMatrix;
253 
255  /* Same size as mCPMatrix */
256  QList< QList<bool> > mCPLegalMatrix;
257 
259  /* Warning: using QList is slow on access */
260  QgsPointXY *pHelperTop = nullptr;
261 
263  /* Warning: using QList is slow on access */
264  QgsPointXY *pHelperBottom = nullptr;
265 
267  int mHelperTopRow;
268 
270  int mCPCols;
272  int mCPRows;
273 
275  double mSqrTolerance;
276 
278  double mMaxSrcXRes;
279  double mMaxSrcYRes;
280 
281 };
282 
284 #endif
285 
286 #endif
287 
int precision
A rectangle specified with double values.
Definition: qgsrectangle.h:40
Precision precision() const
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination CRS.
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:58
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...
Precision
Precision defines if each pixel is reprojected or approximate reprojection based on an approximation ...
#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.