Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport release-3_40] show warning if float raster is used as input in zonal histogram algorithm (fix #30822) #60234

Open
wants to merge 3 commits into
base: release-3_40
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading