QGIS API Documentation 3.36.0-Maidenhead (09951dc0acf)
Loading...
Searching...
No Matches
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"
34#include "qgsrasterinterface.h"
35
36#include <cmath>
37
38class QgsPointXY;
39
47class CORE_EXPORT QgsRasterProjector : public QgsRasterInterface
48{
49 Q_GADGET
50
51 public:
52
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
132
138class ProjectorData
139{
140 public:
142 ProjectorData( const QgsRectangle &extent, int width, int height, QgsRasterInterface *input, const QgsCoordinateTransform &inverseCt, QgsRasterProjector::Precision precision, QgsRasterBlockFeedback *feedback = nullptr );
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
201 bool checkCols( const QgsCoordinateTransform &ct );
202
207 bool checkRows( const QgsCoordinateTransform &ct );
208
210 void calcHelper( int matrixRow, QgsPointXY *points );
211
213 void nextHelper();
214
216 QString cpToString() const;
217
222 bool mApproximate;
223
225 QgsCoordinateTransform mInverseCt;
226
228 QgsRectangle mDestExtent;
229
231 QgsRectangle mSrcExtent;
232
234 QgsRectangle mExtent;
235
237 int mDestRows;
238
240 int mDestCols;
241
243 double mDestXRes;
244
246 double mDestYRes;
247
249 int mSrcRows;
250
252 int mSrcCols;
253
255 double mSrcXRes;
256
258 double mSrcYRes;
259
261 double mDestRowsPerMatrixRow;
262
264 double mDestColsPerMatrixCol;
265
267 QList< QList<QgsPointXY> > mCPMatrix;
268
270 /* Same size as mCPMatrix */
271 QList< QList<bool> > mCPLegalMatrix;
272
274 /* Warning: using QList is slow on access */
275 QgsPointXY *pHelperTop = nullptr;
276
278 /* Warning: using QList is slow on access */
279 QgsPointXY *pHelperBottom = nullptr;
280
282 int mHelperTopRow;
283
285 int mCPCols;
287 int mCPRows;
288
290 double mSqrTolerance;
291
293 double mMaxSrcXRes;
294 double mMaxSrcYRes;
295
296};
297
299#endif
300
301#endif
302
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
This class represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
Class for doing transforms between two map coordinate systems.
A class to represent a 2D point.
Definition qgspointxy.h:60
Feedback object tailored for raster block reading.
Raster data container.
Base class for processing filters like renderers, reprojector, resampler etc.
virtual QgsRasterInterface * clone() const =0
Clone itself, create deep copy.
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.
QgsRasterProjector implements approximate projection support for it calculates grid of points in sour...
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination CRS.
void setPrecision(Precision precision)
Precision
Precision defines if each pixel is reprojected or approximate reprojection based on an approximation ...
Precision precision() const
A rectangle specified with double values.
#define SIP_DEPRECATED
Definition qgis_sip.h:106
#define SIP_OUT
Definition qgis_sip.h:58
#define SIP_FACTORY
Definition qgis_sip.h:76
int precision