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_14] Fix raster quantile with float #37472

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/core/raster/qgsrasterinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ void QgsRasterInterface::initHistogram( QgsRasterHistogram &histogram,
{
// Calc resolution from theSampleSize
double xRes, yRes;
xRes = yRes = std::sqrt( ( finalExtent.width() * finalExtent.height() ) / sampleSize );
xRes = yRes = std::sqrt( ( static_cast<double>( finalExtent.width( ) ) * finalExtent.height() ) / sampleSize );

// But limit by physical resolution
if ( capabilities() & Size )
Expand Down Expand Up @@ -336,7 +336,7 @@ void QgsRasterInterface::initHistogram( QgsRasterHistogram &histogram,
}
QgsDebugMsgLevel( QStringLiteral( "theHistogram.width = %1 histogram.height = %2" ).arg( histogram.width ).arg( histogram.height ), 4 );

int myBinCount = binCount;
qint64 myBinCount = binCount;
if ( myBinCount == 0 )
{
// TODO: this was OK when stats/histogram were calced in provider,
Expand All @@ -359,16 +359,17 @@ void QgsRasterInterface::initHistogram( QgsRasterHistogram &histogram,
mySrcDataType == Qgis::Int16 || mySrcDataType == Qgis::Int32 ||
mySrcDataType == Qgis::UInt16 || mySrcDataType == Qgis::UInt32 ) )
{
myBinCount = std::min( histogram.width * histogram.height, static_cast<int>( std::ceil( histogram.maximum - histogram.minimum + 1 ) ) );
myBinCount = std::min( static_cast<qint64>( histogram.width ) * histogram.height, static_cast<qint64>( std::ceil( histogram.maximum - histogram.minimum + 1 ) ) );
}
else
{
// This is for not integer types:
myBinCount = std::min( 2000, histogram.width * histogram.height );
// This is for not integer types
myBinCount = static_cast<qint64>( histogram.width ) * static_cast<qint64>( histogram.height );
}
}
}
histogram.binCount = myBinCount;
// Hard limit 10'000'000
histogram.binCount = static_cast<int>( std::min( 10000000LL, myBinCount ) );
QgsDebugMsgLevel( QStringLiteral( "theHistogram.binCount = %1" ).arg( histogram.binCount ), 4 );
}

Expand Down