QGIS API Documentation 4.1.0-Master (60fea48833c)
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 <cmath>
27
28#include "qgis_core.h"
29#include "qgis_sip.h"
32#include "qgsrasterinterface.h"
33#include "qgsrectangle.h"
34
35#include <QList>
36#include <QVector>
37
38class QgsPointXY;
39
50class CORE_EXPORT QgsRasterProjector : public QgsRasterInterface
51{
52 Q_GADGET
53
54 public:
60 {
62 Exact = 1,
63 };
64 Q_ENUM( Precision )
65
67
68 QgsRasterProjector *clone() const override SIP_FACTORY;
69
70 int bandCount() const override;
71
72 Qgis::DataType dataType( int bandNo ) const override;
73
78 Q_DECL_DEPRECATED void setCrs( const QgsCoordinateReferenceSystem &srcCRS, const QgsCoordinateReferenceSystem &destCRS, int srcDatumTransform = -1, int destDatumTransform = -1 ) SIP_DEPRECATED;
79
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, QgsRectangle &destExtent SIP_OUT, int &destXSize SIP_OUT, int &destYSize SIP_OUT );
101
103 static bool extentSize( const QgsCoordinateTransform &ct, const QgsRectangle &srcExtent, int srcXSize, int srcYSize, QgsRectangle &destExtent SIP_OUT, int &destXSize SIP_OUT, int &destYSize SIP_OUT );
104
105 private:
108
111
113 Q_DECL_DEPRECATED int mSrcDatumTransform = -1;
114
116 Q_DECL_DEPRECATED int mDestDatumTransform = -1;
117
119 Precision mPrecision = Approximate;
120
121 QgsCoordinateTransformContext mTransformContext;
122};
123
124
125#ifndef SIP_RUN
127
133class ProjectorData
134{
135 public:
137 ProjectorData(
138 const QgsRectangle &extent, int width, int height, QgsRasterInterface *input, const QgsCoordinateTransform &inverseCt, QgsRasterProjector::Precision precision, QgsRasterBlockFeedback *feedback = nullptr
139 );
140 ~ProjectorData();
141
142 ProjectorData( const ProjectorData &other ) = delete;
143 ProjectorData &operator=( const ProjectorData &other ) = delete;
144
150 bool srcRowCol( int destRow, int destCol, int *srcRow, int *srcCol );
151
152 QgsRectangle srcExtent() const { return mSrcExtent; }
153 int srcRows() const { return mSrcRows; }
154 int srcCols() const { return mSrcCols; }
155
156 private:
158 void destPointOnCPMatrix( int row, int col, double *theX, double *theY ) const;
159
161 int matrixRow( int destRow ) const;
162
164 int matrixCol( int destCol ) const;
165
167 inline bool preciseSrcRowCol( int destRow, int destCol, int *srcRow, int *srcCol );
168
170 inline bool approximateSrcRowCol( int destRow, int destCol, int *srcRow, int *srcCol );
171
173 void insertRows( const QgsCoordinateTransform &ct );
174
176 void insertCols( const QgsCoordinateTransform &ct );
177
179 void calcCP( int row, int col, const QgsCoordinateTransform &ct );
180
182 bool calcRow( int row, const QgsCoordinateTransform &ct );
183
185 bool calcCol( int col, const QgsCoordinateTransform &ct );
186
188 void calcSrcExtent();
189
191 void calcSrcRowsCols();
192
197 bool checkCols( const QgsCoordinateTransform &ct ) const;
198
203 bool checkRows( const QgsCoordinateTransform &ct ) const;
204
206 void calcHelper( int matrixRow, QgsPointXY *points );
207
209 void nextHelper();
210
212 QString cpToString() const;
213
218 bool mApproximate = false;
219
221 QgsCoordinateTransform mInverseCt;
222
224 QgsRectangle mDestExtent;
225
227 QgsRectangle mSrcExtent;
228
230 QgsRectangle mExtent;
231
233 int mDestRows;
234
236 int mDestCols;
237
239 double mDestXRes = 0.0;
240
242 double mDestYRes = 0.0;
243
245 int mSrcRows = 0;
246
248 int mSrcCols = 0;
249
251 double mSrcXRes = 0.0;
252
254 double mSrcYRes = 0.0;
255
257 double mDestRowsPerMatrixRow = 0.0;
258
260 double mDestColsPerMatrixCol = 0.0;
261
263 QList< QList<QgsPointXY> > mCPMatrix;
264
266 /* Same size as mCPMatrix */
267 QList< QList<bool> > mCPLegalMatrix;
268
270 /* Warning: using QList is slow on access */
271 QgsPointXY *pHelperTop = nullptr;
272
274 /* Warning: using QList is slow on access */
275 QgsPointXY *pHelperBottom = nullptr;
276
278 int mHelperTopRow = 0;
279
281 int mCPCols = 0;
283 int mCPRows = 0;
284
286 double mSqrTolerance = 0.0;
287
289 double mMaxSrcXRes = 0;
290 double mMaxSrcYRes = 0;
291};
292
294#endif
295
296#endif
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:62
Represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
Handles coordinate transforms between two coordinate systems.
Represents a 2D point.
Definition qgspointxy.h:62
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.
QgsRasterInterface(QgsRasterInterface *input=nullptr)
Implements approximate projection support for optimised raster transformation.
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination CRS.
QgsCoordinateReferenceSystem sourceCrs() const
Returns the source CRS.
void setPrecision(Precision precision)
Precision
Precision defines if each pixel is reprojected or approximate reprojection based on an approximation ...
@ Exact
Exact, precise but slow.
@ Approximate
Approximate (default), fast but possibly inaccurate.
Precision precision() const
Q_DECL_DEPRECATED void setCrs(const QgsCoordinateReferenceSystem &srcCRS, const QgsCoordinateReferenceSystem &destCRS, int srcDatumTransform=-1, int destDatumTransform=-1)
Sets the source and destination CRS.
A rectangle specified with double values.
#define SIP_DEPRECATED
Definition qgis_sip.h:113
#define SIP_OUT
Definition qgis_sip.h:57
#define SIP_FACTORY
Definition qgis_sip.h:83