File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -2353,6 +2353,14 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
2353
2353
mRasterType = GrayOrUndefined;
2354
2354
}
2355
2355
2356
+ // Set min/max values for single band if we have them ready (no need to calculate which is slow)
2357
+ // don't set min/max on multiband even if available because it would cause stretch of bands and thus colors distortion
2358
+ if ( mDataProvider ->bandCount () == 1 && ( mDataProvider ->capabilities () & QgsRasterDataProvider::ExactMinimumMaximum ) )
2359
+ {
2360
+ setMinimumValue ( 1 , mDataProvider ->minimumValue ( 1 ) );
2361
+ setMaximumValue ( 1 , mDataProvider ->maximumValue ( 1 ) );
2362
+ }
2363
+
2356
2364
QgsDebugMsg ( " mRasterType = " + QString::number ( mRasterType ) );
2357
2365
if ( mRasterType == ColorLayer )
2358
2366
{
@@ -2434,6 +2442,14 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
2434
2442
mDrawingStyle = SingleBandGray; // sensible default
2435
2443
mGrayBandName = bandName ( 1 );
2436
2444
2445
+ // If we have min/max available (without calculation), it is better to use StretchToMinimumMaximum
2446
+ // TODO: in GUI there is 'Contrast enhancement - Default' which is overwritten here
2447
+ // and that is confusing
2448
+ if ( mDataProvider ->capabilities () & QgsRasterDataProvider::ExactMinimumMaximum )
2449
+ {
2450
+ setContrastEnhancementAlgorithm ( QgsContrastEnhancement::StretchToMinimumMaximum );
2451
+ }
2452
+
2437
2453
// read standard deviations
2438
2454
if ( mContrastEnhancementAlgorithm == QgsContrastEnhancement::StretchToMinimumMaximum )
2439
2455
{
You can’t perform that action at this time.
0 commit comments