Skip to content

Commit

Permalink
Merge pull request #60212 from alexbruy/processing-zonal-histogram-pr…
Browse files Browse the repository at this point in the history
…ecision

show warning if float raster is used as input in zonal histogram algorithm (fix #30822)
  • Loading branch information
alexbruy authored Jan 23, 2025
2 parents 510ef31 + 69f7317 commit 836a197
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/analysis/processing/qgsalgorithmzonalhistogram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ QgsZonalHistogramAlgorithm *QgsZonalHistogramAlgorithm::createInstance() const
return new QgsZonalHistogramAlgorithm();
}

bool QgsZonalHistogramAlgorithm::prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback * )
bool QgsZonalHistogramAlgorithm::prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
{
QgsRasterLayer *layer = parameterAsRasterLayer( parameters, QStringLiteral( "INPUT_RASTER" ), context );
if ( !layer )
Expand All @@ -84,6 +84,21 @@ bool QgsZonalHistogramAlgorithm::prepareAlgorithm( const QVariantMap &parameters
mCellSizeY = std::abs( layer->rasterUnitsPerPixelX() );
mNbCellsXProvider = mRasterInterface->xSize();
mNbCellsYProvider = mRasterInterface->ySize();
Qgis::DataType dataType = mRasterInterface->dataType( mRasterBand );

switch ( dataType )
{
case Qgis::DataType::Byte:
case Qgis::DataType::Int16:
case Qgis::DataType::UInt16:
case Qgis::DataType::Int32:
case Qgis::DataType::UInt32:
break;
default:
feedback->pushWarning( QObject::tr( "The input raster is a floating-point raster. Such rasters are not suitable for use with zonal histogram algorithm.\n"
"Please use Round raster or Reclassify by table tools to reduce number of decimal places or define histogram bins." ) );
break;
}

return true;
}
Expand Down

0 comments on commit 836a197

Please sign in to comment.