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 @@ -2250,6 +2250,14 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
22502250 mRasterType = GrayOrUndefined;
22512251 }
22522252
2253+ // Set min/max values for single band if we have them ready (no need to calculate which is slow)
2254+ // don't set min/max on multiband even if available because it would cause stretch of bands and thus colors distortion
2255+ if ( mDataProvider ->bandCount () == 1 && ( mDataProvider ->capabilities () & QgsRasterDataProvider::ExactMinimumMaximum ) )
2256+ {
2257+ setMinimumValue ( 1 , mDataProvider ->minimumValue ( 1 ) );
2258+ setMaximumValue ( 1 , mDataProvider ->maximumValue ( 1 ) );
2259+ }
2260+
22532261 QgsDebugMsg ( " mRasterType = " + QString::number ( mRasterType ) );
22542262 if ( mRasterType == ColorLayer )
22552263 {
@@ -2331,6 +2339,14 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
23312339 mDrawingStyle = SingleBandGray; // sensible default
23322340 mGrayBandName = bandName ( 1 );
23332341
2342+ // If we have min/max available (without calculation), it is better to use StretchToMinimumMaximum
2343+ // TODO: in GUI there is 'Contrast enhancement - Default' which is overwritten here
2344+ // and that is confusing
2345+ if ( mDataProvider ->capabilities () & QgsRasterDataProvider::ExactMinimumMaximum )
2346+ {
2347+ setContrastEnhancementAlgorithm ( QgsContrastEnhancement::StretchToMinimumMaximum );
2348+ }
2349+
23342350 // read standard deviations
23352351 if ( mContrastEnhancementAlgorithm == QgsContrastEnhancement::StretchToMinimumMaximum )
23362352 {
You can’t perform that action at this time.
0 commit comments