QGIS API Documentation  2.99.0-Master (01468d0)
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 
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 SIP_FACTORY;
83 
85  bool destExtentSize( const QgsRectangle &srcExtent, int srcXSize, int srcYSize,
86  QgsRectangle &destExtent SIP_OUT, int &destXSize SIP_OUT, int &destYSize SIP_OUT );
87 
89  static bool extentSize( const QgsCoordinateTransform &ct,
90  const QgsRectangle &srcExtent, int srcXSize, int srcYSize,
91  QgsRectangle &destExtent SIP_OUT, int &destXSize SIP_OUT, int &destYSize SIP_OUT );
92 
93  private:
94 
97 
100 
102  int mSrcDatumTransform;
103 
105  int mDestDatumTransform;
106 
108  Precision mPrecision;
109 
110 };
111 
112 
113 #ifndef SIP_RUN
114 
121 class ProjectorData
122 {
123  public:
125  ProjectorData( const QgsRectangle &extent, int width, int height, QgsRasterInterface *input, const QgsCoordinateTransform &inverseCt, QgsRasterProjector::Precision precision );
126  ~ProjectorData();
127 
128  ProjectorData( const ProjectorData &other ) = delete;
129  ProjectorData &operator=( const ProjectorData &other ) = delete;
130 
135  bool srcRowCol( int destRow, int destCol, int *srcRow, int *srcCol );
136 
137  QgsRectangle srcExtent() const { return mSrcExtent; }
138  int srcRows() const { return mSrcRows; }
139  int srcCols() const { return mSrcCols; }
140 
141  private:
142 
144  void destPointOnCPMatrix( int row, int col, double *theX, double *theY );
145 
147  int matrixRow( int destRow );
148  int matrixCol( int destCol );
149 
151  inline bool preciseSrcRowCol( int destRow, int destCol, int *srcRow, int *srcCol );
152 
154  inline bool approximateSrcRowCol( int destRow, int destCol, int *srcRow, int *srcCol );
155 
157  void insertRows( const QgsCoordinateTransform &ct );
158 
160  void insertCols( const QgsCoordinateTransform &ct );
161 
163  void calcCP( int row, int col, const QgsCoordinateTransform &ct );
164 
166  bool calcRow( int row, const QgsCoordinateTransform &ct );
167 
169  bool calcCol( int col, const QgsCoordinateTransform &ct );
170 
172  void calcSrcExtent();
173 
175  void calcSrcRowsCols();
176 
179  bool checkCols( const QgsCoordinateTransform &ct );
180 
183  bool checkRows( const QgsCoordinateTransform &ct );
184 
186  void calcHelper( int matrixRow, QgsPointXY *points );
187 
189  void nextHelper();
190 
192  QString cpToString();
193 
196  bool mApproximate;
197 
199  QgsCoordinateTransform mInverseCt;
200 
202  QgsRectangle mDestExtent;
203 
205  QgsRectangle mSrcExtent;
206 
208  QgsRectangle mExtent;
209 
211  int mDestRows;
212 
214  int mDestCols;
215 
217  double mDestXRes;
218 
220  double mDestYRes;
221 
223  int mSrcRows;
224 
226  int mSrcCols;
227 
229  double mSrcXRes;
230 
232  double mSrcYRes;
233 
235  double mDestRowsPerMatrixRow;
236 
238  double mDestColsPerMatrixCol;
239 
241  QList< QList<QgsPointXY> > mCPMatrix;
242 
244  /* Same size as mCPMatrix */
245  QList< QList<bool> > mCPLegalMatrix;
246 
248  /* Warning: using QList is slow on access */
249  QgsPointXY *pHelperTop = nullptr;
250 
252  /* Warning: using QList is slow on access */
253  QgsPointXY *pHelperBottom = nullptr;
254 
256  int mHelperTopRow;
257 
259  int mCPCols;
261  int mCPRows;
262 
264  double mSqrTolerance;
265 
267  double mMaxSrcXRes;
268  double mMaxSrcYRes;
269 
270 };
271 
273 #endif
274 
275 #endif
276 
A rectangle specified with double values.
Definition: qgsrectangle.h:38
Precision precision() const
A class to represent a 2D point.
Definition: qgspointxy.h:42
The Qgis class provides global constants for use throughout the application.
Definition: qgis.h:54
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.