QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
Loading...
Searching...
No Matches
qgsrasteriterator.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsrasteriterator.h
3 ---------------------
4 begin : July 2012
5 copyright : (C) 2012 by Marco Hugentobler
6 email : marco dot hugentobler at sourcepole dot ch
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15#ifndef QGSRASTERITERATOR_H
16#define QGSRASTERITERATOR_H
17
18#include "qgis_core.h"
19#include "qgis_sip.h"
20#include "qgsrectangle.h"
21
22#include <QMap>
23
24class QgsMapToPixel;
25class QgsRasterBlock;
30
35class CORE_EXPORT QgsRasterIterator
36{
37 public:
43 QgsRasterIterator( QgsRasterInterface *input, int tileOverlapPixels = 0 );
44
60 void setSnapToPixelFactor( int factor ) { mSnapToPixelFactor = factor > 0 ? factor : 1; }
61
72 int snapToPixelFactor() const { return mSnapToPixelFactor; }
73
92 static QgsRectangle subRegion(
93 const QgsRectangle &rasterExtent,
94 int rasterWidth,
95 int rasterHeight,
96 const QgsRectangle &subRegion,
97 int &subRegionWidth SIP_OUT,
98 int &subRegionHeight SIP_OUT,
99 int &subRegionLeft SIP_OUT,
100 int &subRegionTop SIP_OUT,
101 int resamplingFactor = 1
102 );
103
112 void startRasterRead( int bandNumber, qgssize nCols, qgssize nRows, const QgsRectangle &extent, QgsRasterBlockFeedback *feedback = nullptr );
113
133 bool next( int bandNumber, int &columns SIP_OUT, int &rows SIP_OUT, int &topLeftColumn SIP_OUT, int &topLeftRow SIP_OUT, QgsRectangle &blockExtent SIP_OUT );
134
146 bool readNextRasterPart( int bandNumber, int &nCols, int &nRows, QgsRasterBlock **block SIP_TRANSFERBACK, int &topLeftCol, int &topLeftRow );
147
165 bool readNextRasterPart(
166 int bandNumber,
167 int &nCols,
168 int &nRows,
169 std::unique_ptr< QgsRasterBlock > &block,
170 int &topLeftCol,
171 int &topLeftRow,
172 QgsRectangle *blockExtent = nullptr,
173 int *tileColumns = nullptr,
174 int *tileRows = nullptr,
175 int *tileTopLeftColumn = nullptr,
176 int *tileTopLeftRow = nullptr
177 ) SIP_SKIP;
178
182 void stopRasterRead( int bandNumber );
183
187 const QgsRasterInterface *input() const { return mInput; }
188
194 void setMaximumTileWidth( int w ) { mMaximumTileWidth = w; }
195
201 int maximumTileWidth() const { return mMaximumTileWidth; }
202
208 void setMaximumTileHeight( int h ) { mMaximumTileHeight = h; }
209
215 int maximumTileHeight() const { return mMaximumTileHeight; }
216
224 int blockCountWidth() const { return mNumberBlocksWidth; }
225
233 int blockCountHeight() const { return mNumberBlocksHeight; }
234
242 qgssize blockCount() const { return static_cast< qgssize >( mNumberBlocksHeight ) * mNumberBlocksWidth; }
243
252 double progress( int bandNumber, double currentBlockProgress = -1 ) const;
253
255 static const int DEFAULT_MAXIMUM_TILE_WIDTH = 2000;
256
258 static const int DEFAULT_MAXIMUM_TILE_HEIGHT = 2000;
259
260 private:
261 //Stores information about reading of a raster band. Columns and rows are in unsampled coordinates
262 struct RasterPartInfo
263 {
264 qgssize currentCol;
265 qgssize currentRow;
266 qgssize nCols;
267 qgssize nRows;
268 qgssize iteratedPixels = 0;
269 qgssize previousIteratedPixels = 0;
270 qgssize currentBlockSize = 0;
271 };
272
273 QgsRasterInterface *mInput = nullptr;
274 QMap<int, RasterPartInfo> mRasterPartInfos;
275 QgsRectangle mExtent;
276 QgsRasterBlockFeedback *mFeedback = nullptr;
277
278 int mTileOverlapPixels = 0;
279 int mMaximumTileWidth;
280 int mMaximumTileHeight;
281 int mSnapToPixelFactor = 1;
282
283 int mNumberBlocksWidth = 0;
284 int mNumberBlocksHeight = 0;
285
287 void removePartInfo( int bandNumber );
288 bool readNextRasterPartInternal(
289 int bandNumber,
290 int &nCols,
291 int &nRows,
292 std::unique_ptr<QgsRasterBlock> *block,
293 int &topLeftCol,
294 int &topLeftRow,
295 QgsRectangle *blockExtent,
296 int &tileColumns,
297 int &tileRows,
298 int &tileTopLeftColumn,
299 int &tileTopLeftRow
300 );
301};
302
303#endif // QGSRASTERITERATOR_H
Perform transforms between map coordinates and device coordinates.
Feedback object tailored for raster block reading.
Raster data container.
Base class for processing filters like renderers, reprojector, resampler etc.
int snapToPixelFactor() const
Returns the current "snap to pixel" factor in pixels.
void setSnapToPixelFactor(int factor)
Sets the "snap to pixel" factor in pixels.
qgssize blockCount() const
Returns the total number of blocks required to iterate over the input raster.
QgsRasterIterator(QgsRasterInterface *input, int tileOverlapPixels=0)
Constructor for QgsRasterIterator, iterating over the specified input raster source.
int maximumTileWidth() const
Returns the maximum tile width returned during iteration.
const QgsRasterInterface * input() const
Returns the input raster interface which is being iterated over.
void setMaximumTileWidth(int w)
Sets the maximum tile width returned during iteration.
static const int DEFAULT_MAXIMUM_TILE_WIDTH
Default maximum tile width.
int blockCountWidth() const
Returns the total number of blocks which cover the width of the input raster.
static const int DEFAULT_MAXIMUM_TILE_HEIGHT
Default maximum tile height.
int blockCountHeight() const
Returns the total number of blocks which cover the height of the input raster.
int maximumTileHeight() const
Returns the minimum tile width returned during iteration.
void setMaximumTileHeight(int h)
Sets the minimum tile height returned during iteration.
Implements approximate projection support for optimised raster transformation.
A rectangle specified with double values.
unsigned long long qgssize
Qgssize is used instead of size_t, because size_t is stdlib type, unknown by SIP, and it would be har...
Definition qgis.h:7485
#define SIP_SKIP
Definition qgis_sip.h:133
#define SIP_OUT
Definition qgis_sip.h:57
#define SIP_TRANSFERBACK
Definition qgis_sip.h:47
This class provides details of the viewable area that a raster will be rendered into.