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

show warning if float raster is used as input in zonal histogram algorithm (fix #30822) #60212

Merged
merged 3 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
21 changes: 21 additions & 0 deletions src/analysis/processing/qgsalgorithmzonalhistogram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -94,6 +109,12 @@ QVariantMap QgsZonalHistogramAlgorithm::processAlgorithm( const QVariantMap &par
if ( !zones )
throw QgsProcessingException( invalidSourceError( parameters, QStringLiteral( "INPUT_VECTOR" ) ) );

if ( !mIsInteger )
alexbruy marked this conversation as resolved.
Show resolved Hide resolved
{
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;
Expand Down
1 change: 1 addition & 0 deletions src/analysis/processing/qgsalgorithmzonalhistogram.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class QgsZonalHistogramAlgorithm : public QgsProcessingAlgorithm
double mCellSizeY = 0;
double mNbCellsXProvider = 0;
double mNbCellsYProvider = 0;
bool mIsInteger = false;
};

///@endcond PRIVATE
Expand Down
Loading