QGIS API Documentation 3.41.0-Master (3440c17df1d)
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
50class CORE_EXPORT QgsRasterProjector : public QgsRasterInterface
51{
52 Q_GADGET
53
54 public:
55
61 {
62 Approximate = 0,
63 Exact = 1,
64 };
65 Q_ENUM( Precision )
66
68
69 QgsRasterProjector *clone() const override SIP_FACTORY;
70
71 int bandCount() const override;
72
73 Qgis::DataType dataType( int bandNo ) const override;
74
79 Q_DECL_DEPRECATED void setCrs( const QgsCoordinateReferenceSystem &srcCRS, const QgsCoordinateReferenceSystem &destCRS,
80 int srcDatumTransform = -1, int destDatumTransform = -1 ) SIP_DEPRECATED;
81
86 void setCrs( const QgsCoordinateReferenceSystem &srcCRS, const QgsCoordinateReferenceSystem &destCRS,
87 QgsCoordinateTransformContext transformContext );
88
90 QgsCoordinateReferenceSystem sourceCrs() const { return mSrcCRS; }
91
93 QgsCoordinateReferenceSystem destinationCrs() const { return mDestCRS; }
94
95 Precision precision() const { return mPrecision; }
96 void setPrecision( Precision precision ) { mPrecision = precision; }
97 // Translated precision mode, for use in ComboBox etc.
98 static QString precisionLabel( Precision precision );
99
100 QgsRasterBlock *block( int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback = nullptr ) override SIP_FACTORY;
101
103 bool destExtentSize( const QgsRectangle &srcExtent, int srcXSize, int srcYSize,
104 QgsRectangle &destExtent SIP_OUT, int &destXSize SIP_OUT, int &destYSize SIP_OUT );
105
107 static bool extentSize( const QgsCoordinateTransform &ct,
108 const QgsRectangle &srcExtent, int srcXSize, int srcYSize,
109 QgsRectangle &destExtent SIP_OUT, int &destXSize SIP_OUT, int &destYSize SIP_OUT );
110
111 private:
112
115
118
120 Q_DECL_DEPRECATED int mSrcDatumTransform = -1;
121
123 Q_DECL_DEPRECATED int mDestDatumTransform = -1;
124
126 Precision mPrecision = Approximate;
127
128 QgsCoordinateTransformContext mTransformContext;
129
130};
131
132
133#ifndef SIP_RUN
135
141class ProjectorData
142{
143 public:
145 ProjectorData( const QgsRectangle &extent, int width, int height, QgsRasterInterface *input, const QgsCoordinateTransform &inverseCt, QgsRasterProjector::Precision precision, QgsRasterBlockFeedback *feedback = nullptr );
146 ~ProjectorData();
147
148 ProjectorData( const ProjectorData &other ) = delete;
149 ProjectorData &operator=( const ProjectorData &other ) = delete;
150
156 bool srcRowCol( int destRow, int destCol, int *srcRow, int *srcCol );
157
158 QgsRectangle srcExtent() const { return mSrcExtent; }
159 int srcRows() const { return mSrcRows; }
160 int srcCols() const { return mSrcCols; }
161
162 private:
163
165 void destPointOnCPMatrix( int row, int col, double *theX, double *theY );
166
168 int matrixRow( int destRow );
169
171 int matrixCol( int destCol );
172
174 inline bool preciseSrcRowCol( int destRow, int destCol, int *srcRow, int *srcCol );
175
177 inline bool approximateSrcRowCol( int destRow, int destCol, int *srcRow, int *srcCol );
178
180 void insertRows( const QgsCoordinateTransform &ct );
181
183 void insertCols( const QgsCoordinateTransform &ct );
184
186 void calcCP( int row, int col, const QgsCoordinateTransform &ct );
187
189 bool calcRow( int row, const QgsCoordinateTransform &ct );
190
192 bool calcCol( int col, const QgsCoordinateTransform &ct );
193
195 void calcSrcExtent();
196
198 void calcSrcRowsCols();
199
204 bool checkCols( const QgsCoordinateTransform &ct );
205
210 bool checkRows( const QgsCoordinateTransform &ct );
211
213 void calcHelper( int matrixRow, QgsPointXY *points );
214
216 void nextHelper();
217
219 QString cpToString() const;
220
225 bool mApproximate;
226
228 QgsCoordinateTransform mInverseCt;
229
231 QgsRectangle mDestExtent;
232
234 QgsRectangle mSrcExtent;
235
237 QgsRectangle mExtent;
238
240 int mDestRows;
241
243 int mDestCols;
244
246 double mDestXRes;
247
249 double mDestYRes;
250
252 int mSrcRows;
253
255 int mSrcCols;
256
258 double mSrcXRes;
259
261 double mSrcYRes;
262
264 double mDestRowsPerMatrixRow;
265
267 double mDestColsPerMatrixCol;
268
270 QList< QList<QgsPointXY> > mCPMatrix;
271
273 /* Same size as mCPMatrix */
274 QList< QList<bool> > mCPLegalMatrix;
275
277 /* Warning: using QList is slow on access */
278 QgsPointXY *pHelperTop = nullptr;
279
281 /* Warning: using QList is slow on access */
282 QgsPointXY *pHelperBottom = nullptr;
283
285 int mHelperTopRow;
286
288 int mCPCols;
290 int mCPRows;
291
293 double mSqrTolerance;
294
296 double mMaxSrcXRes;
297 double mMaxSrcYRes;
298
299};
300
302#endif
303
304#endif
305
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.
Implements approximate projection support for optimised raster transformation.
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