29 void QgsReclassifyUtils::reportClasses(
const QVector<QgsReclassifyUtils::RasterClass> &classes,
QgsProcessingFeedback *feedback )
32 feedback->
pushInfo( QObject::tr(
"Using classes:" ) );
33 for (
const RasterClass &
c : classes )
35 feedback->
pushInfo( QStringLiteral(
" %1) %2 %3 %4" ).arg( i )
37 .arg( QChar( 0x2192 ) )
43 void QgsReclassifyUtils::checkForOverlaps(
const QVector<QgsReclassifyUtils::RasterClass> &classes,
QgsProcessingFeedback *feedback )
46 for (
int i = 0; i < classes.count() - 1; i++ )
48 for (
int j = i + 1; j < classes.count(); j++ )
50 const QgsReclassifyUtils::RasterClass &class1 = classes.at( i );
51 const QgsReclassifyUtils::RasterClass &class2 = classes.at( j );
52 if ( class1.overlaps( class2 ) )
54 feedback->
reportError( QObject::tr(
"Warning: Class %1 (%2) overlaps with class %3 (%4)" ).arg( i + 1 )
55 .arg( class1.asText() )
57 .arg( class2.asText() ) );
63 void QgsReclassifyUtils::reclassify(
const QVector<QgsReclassifyUtils::RasterClass> &classes,
QgsRasterInterface *sourceRaster,
int band,
64 const QgsRectangle &extent,
int sourceWidthPixels,
int sourceHeightPixels,
72 iter.startRasterRead( band, sourceWidthPixels, sourceHeightPixels, extent );
74 int nbBlocksWidth =
static_cast< int >( std::ceil( 1.0 * sourceWidthPixels / maxWidth ) );
75 int nbBlocksHeight =
static_cast< int >( std::ceil( 1.0 * sourceHeightPixels / maxHeight ) );
76 int nbBlocks = nbBlocksWidth * nbBlocksHeight;
83 std::unique_ptr< QgsRasterBlock > rasterBlock;
84 bool reclassed =
false;
85 bool isNoData =
false;
86 while ( iter.readNextRasterPart( band, iterCols, iterRows, rasterBlock, iterLeft, iterTop ) )
89 feedback->
setProgress( 100 * ( ( iterTop / maxHeight * nbBlocksWidth ) + iterLeft / maxWidth ) / nbBlocks );
92 std::unique_ptr< QgsRasterBlock > reclassifiedBlock = qgis::make_unique< QgsRasterBlock >( destinationRaster->
dataType( 1 ), iterCols, iterRows );
94 for (
int row = 0; row < iterRows; row++ )
98 for (
int column = 0; column < iterCols; column++ )
100 const double value = rasterBlock->valueAndNoData( row, column, isNoData );
102 reclassifiedBlock->setValue( row, column, destNoDataValue );
105 double newValue = reclassifyValue( classes, value, reclassed );
107 reclassifiedBlock->setValue( row, column, newValue );
109 reclassifiedBlock->setValue( row, column, useNoDataForMissingValues ? destNoDataValue : value );
113 destinationRaster->
writeBlock( reclassifiedBlock.get(), 1, iterLeft, iterTop );
A rectangle specified with double values.
Base class for providing feedback from a processing algorithm.
Iterator for sequentially processing raster cells.
void setProgress(double progress)
Sets the current progress for the feedback object.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
virtual bool setEditable(bool enabled)
Turns on/off editing mode of the provider.
virtual void pushInfo(const QString &info)
Pushes a general informational message from the algorithm.
static const int DEFAULT_MAXIMUM_TILE_HEIGHT
Default maximum tile height.
Base class for processing filters like renderers, reprojector, resampler etc.
bool isCanceled() const
Tells whether the operation has been canceled already.
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.
bool writeBlock(QgsRasterBlock *block, int band, int xOffset=0, int yOffset=0)
Writes pixel data from a raster block into the provider data source.
static const int DEFAULT_MAXIMUM_TILE_WIDTH
Default maximum tile width.
Qgis::DataType dataType(int bandNo) const override=0
Returns data type for the band specified by number.
Base class for raster data providers.