show warning when floating-point raster is used as an input in zonal

histoghram algorithm (fix #30822)
This commit is contained in:
Alexander Bruy 2025-01-22 14:05:03 +00:00
parent ef0dd0355e
commit 93425063f3
2 changed files with 22 additions and 0 deletions

View File

@ -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:
mIsInteger = true;
break;
default:
mIsInteger = false;
break;
}
return true;
}
@ -94,6 +109,12 @@ QVariantMap QgsZonalHistogramAlgorithm::processAlgorithm( const QVariantMap &par
if ( !zones )
throw QgsProcessingException( invalidSourceError( parameters, QStringLiteral( "INPUT_VECTOR" ) ) );
if ( !mIsInteger )
{
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." ) );
}
const long count = zones->featureCount();
const double step = count > 0 ? 100.0 / count : 1;
long current = 0;

View File

@ -56,6 +56,7 @@ class QgsZonalHistogramAlgorithm : public QgsProcessingAlgorithm
double mCellSizeY = 0;
double mNbCellsXProvider = 0;
double mNbCellsYProvider = 0;
bool mIsInteger = false;
};
///@endcond PRIVATE