mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-15 00:07:25 -05:00
show warning when floating-point raster is used as an input in zonal
histoghram algorithm (fix #30822)
This commit is contained in:
parent
ef0dd0355e
commit
93425063f3
@ -84,6 +84,21 @@ bool QgsZonalHistogramAlgorithm::prepareAlgorithm( const QVariantMap ¶meters
|
||||
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;
|
||||
|
||||
@ -56,6 +56,7 @@ class QgsZonalHistogramAlgorithm : public QgsProcessingAlgorithm
|
||||
double mCellSizeY = 0;
|
||||
double mNbCellsXProvider = 0;
|
||||
double mNbCellsYProvider = 0;
|
||||
bool mIsInteger = false;
|
||||
};
|
||||
|
||||
///@endcond PRIVATE
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user