QGIS API Documentation  3.1.0-Master (f35745f)
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  int matrixCol( int destCol );
155 
157  inline bool preciseSrcRowCol( int destRow, int destCol, int *srcRow, int *srcCol );
158 
160  inline bool approximateSrcRowCol( int destRow, int destCol, int *srcRow, int *srcCol );
161 
163  void insertRows( const QgsCoordinateTransform &ct );
164 
166  void insertCols( const QgsCoordinateTransform &ct );
167 
169  void calcCP( int row, int col, const QgsCoordinateTransform &ct );
170 
172  bool calcRow( int row, const QgsCoordinateTransform &ct );
173 
175  bool calcCol( int col, const QgsCoordinateTransform &ct );
176 
178  void calcSrcExtent();
179 
181  void calcSrcRowsCols();
182 
186  bool checkCols( const QgsCoordinateTransform &ct );
187 
191  bool checkRows( const QgsCoordinateTransform &ct );
192 
194  void calcHelper( int matrixRow, QgsPointXY *points );
195 
197  void nextHelper();
198 
200  QString cpToString();
201 
205  bool mApproximate;
206 
208  QgsCoordinateTransform mInverseCt;
209 
211  QgsRectangle mDestExtent;
212 
214  QgsRectangle mSrcExtent;
215 
217  QgsRectangle mExtent;
218 
220  int mDestRows;
221 
223  int mDestCols;
224 
226  double mDestXRes;
227 
229  double mDestYRes;
230 
232  int mSrcRows;
233 
235  int mSrcCols;
236 
238  double mSrcXRes;
239 
241  double mSrcYRes;
242 
244  double mDestRowsPerMatrixRow;
245 
247  double mDestColsPerMatrixCol;
248 
250  QList< QList<QgsPointXY> > mCPMatrix;
251 
253  /* Same size as mCPMatrix */
254  QList< QList<bool> > mCPLegalMatrix;
255 
257  /* Warning: using QList is slow on access */
258  QgsPointXY *pHelperTop = nullptr;
259 
261  /* Warning: using QList is slow on access */
262  QgsPointXY *pHelperBottom = nullptr;
263 
265  int mHelperTopRow;
266 
268  int mCPCols;
270  int mCPRows;
271 
273  double mSqrTolerance;
274 
276  double mMaxSrcXRes;
277  double mMaxSrcYRes;
278 
279 };
280 
282 #endif
283 
284 #endif
285 
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.