@@ -595,201 +595,6 @@ QString QgsRasterLayer::contrastEnhancementAlgorithmAsString() const
595
595
void QgsRasterLayer::setRendererForDrawingStyle ( const DrawingStyle & theDrawingStyle )
596
596
{
597
597
setRenderer ( QgsRasterRendererRegistry::instance ()->defaultRendererForDrawingStyle ( theDrawingStyle, mDataProvider ) );
598
- #if 0
599
- QgsRasterRenderer* renderer = 0;
600
-
601
- switch ( theDrawingStyle )
602
- {
603
- case PalettedColor:
604
- {
605
- int grayBand = bandNumber( grayBandName() );
606
- QgsColorRampShader* colorRampShader = dynamic_cast<QgsColorRampShader*>( rasterShader()->rasterShaderFunction() );
607
- if ( colorRampShader )
608
- {
609
- QList<QgsColorRampShader::ColorRampItem> colorEntries = colorRampShader->colorRampItemList();
610
-
611
- //go through list and take maximum value (it could be that entries don't start at 0 or indices are not contiguous)
612
- int colorArraySize = 0;
613
- QList<QgsColorRampShader::ColorRampItem>::const_iterator colorIt = colorEntries.constBegin();
614
- for ( ; colorIt != colorEntries.constEnd(); ++colorIt )
615
- {
616
- if ( colorIt->value > colorArraySize )
617
- {
618
- colorArraySize = ( int )( colorIt->value );
619
- }
620
- }
621
-
622
- colorArraySize += 1; //usually starts at 0
623
- QColor* colorArray = new QColor[ colorArraySize ];
624
- colorIt = colorEntries.constBegin();
625
- for ( ; colorIt != colorEntries.constEnd(); ++colorIt )
626
- {
627
- colorArray[( int )( colorIt->value )] = colorIt->color;
628
- }
629
-
630
- renderer = new QgsPalettedRasterRenderer( mDataProvider,
631
- grayBand,
632
- colorArray,
633
- colorArraySize );
634
- }
635
- else //try to get it from the color table
636
- {
637
- QList<QgsColorRampShader::ColorRampItem> itemList = mRasterStatsList[ grayBand - 1].colorTable;
638
- QColor* colorArray = new QColor[itemList.size()];
639
- QList<QgsColorRampShader::ColorRampItem>::const_iterator colorIt = itemList.constBegin();
640
- for ( ; colorIt != itemList.constEnd(); ++colorIt )
641
- {
642
- colorArray[( int )colorIt->value] = colorIt->color;
643
- }
644
- renderer = new QgsPalettedRasterRenderer( mDataProvider,
645
- grayBand, colorArray, itemList.size() );
646
- }
647
- break;
648
- }
649
- case MultiBandSingleBandGray:
650
- case SingleBandGray:
651
- {
652
- int grayBand = bandNumber( mGrayBandName );
653
- renderer = new QgsSingleBandGrayRenderer( mDataProvider, grayBand );
654
- QgsContrastEnhancement* ce = new QgsContrastEnhancement(( QgsContrastEnhancement::QgsRasterDataType )(
655
- mDataProvider->dataType( grayBand ) ) );
656
- ce->setContrastEnhancementAlgorithm( contrastEnhancementAlgorithm() );
657
- if ( QgsContrastEnhancement::NoEnhancement != contrastEnhancementAlgorithm() && !mUserDefinedGrayMinimumMaximum && mStandardDeviations > 0 )
658
- {
659
- QgsRasterBandStats myGrayBandStats = bandStatistics( grayBand );
660
- ce->setMinimumValue( myGrayBandStats.mean - ( mStandardDeviations * myGrayBandStats.stdDev ) );
661
- ce->setMaximumValue( myGrayBandStats.mean + ( mStandardDeviations * myGrayBandStats.stdDev ) );
662
- }
663
- else if ( QgsContrastEnhancement::NoEnhancement != contrastEnhancementAlgorithm() && !mUserDefinedGrayMinimumMaximum )
664
- {
665
- ce->setMinimumValue( mDataProvider->minimumValue( grayBand ) );
666
- ce->setMaximumValue( mDataProvider->maximumValue( grayBand ) );
667
- }
668
- (( QgsSingleBandGrayRenderer* )renderer )->setContrastEnhancement( ce );
669
- break;
670
- }
671
- case SingleBandPseudoColor:
672
- {
673
- int bandNo = bandNumber( mGrayBandName );
674
- QgsRasterBandStats myRasterBandStats = bandStatistics( bandNo );
675
- double myMinimumValue = 0.0;
676
- double myMaximumValue = 0.0;
677
- //Use standard deviations if set, otherwise, use min max of band
678
- if ( mStandardDeviations > 0 )
679
- {
680
- myMinimumValue = ( myRasterBandStats.mean - ( mStandardDeviations * myRasterBandStats.stdDev ) );
681
- myMaximumValue = ( myRasterBandStats.mean + ( mStandardDeviations * myRasterBandStats.stdDev ) );
682
- }
683
- else
684
- {
685
- myMinimumValue = myRasterBandStats.minimumValue;
686
- myMaximumValue = myRasterBandStats.maximumValue;
687
- }
688
-
689
- mRasterShader->setMinimumValue( myMinimumValue );
690
- mRasterShader->setMaximumValue( myMaximumValue );
691
-
692
- renderer = new QgsSingleBandPseudoColorRenderer( mDataProvider, bandNo, mRasterShader );
693
- break;
694
- }
695
- case MultiBandColor:
696
- {
697
- int red = -1;
698
- QgsContrastEnhancement* redEnhancement = 0;
699
- if ( mRedBandName != TRSTRING_NOT_SET )
700
- {
701
- red = bandNumber( mRedBandName );
702
- if ( contrastEnhancementAlgorithm() != QgsContrastEnhancement::NoEnhancement )
703
- {
704
- QgsContrastEnhancement* bkRedEnhancement = contrastEnhancement( red );
705
- if ( bkRedEnhancement )
706
- {
707
- redEnhancement = new QgsContrastEnhancement(( QgsContrastEnhancement::QgsRasterDataType )(
708
- mDataProvider->dataType( red ) ) );
709
- redEnhancement->setMinimumValue( bkRedEnhancement->minimumValue() );
710
- redEnhancement->setMaximumValue( bkRedEnhancement->maximumValue() );
711
- redEnhancement->setContrastEnhancementAlgorithm( contrastEnhancementAlgorithm() );
712
- }
713
- }
714
- }
715
- int green = -1;
716
- QgsContrastEnhancement* greenEnhancement = 0;
717
- if ( mGreenBandName != TRSTRING_NOT_SET )
718
- {
719
- green = bandNumber( mGreenBandName );
720
- if ( contrastEnhancementAlgorithm() != QgsContrastEnhancement::NoEnhancement )
721
- {
722
- QgsContrastEnhancement* bkGreenEnhancement = contrastEnhancement( green );
723
- if ( bkGreenEnhancement )
724
- {
725
- greenEnhancement = new QgsContrastEnhancement(( QgsContrastEnhancement::QgsRasterDataType )(
726
- mDataProvider->dataType( green ) ) );
727
- greenEnhancement->setMinimumValue( bkGreenEnhancement->minimumValue() );
728
- greenEnhancement->setMaximumValue( bkGreenEnhancement->maximumValue() );
729
- greenEnhancement->setContrastEnhancementAlgorithm( contrastEnhancementAlgorithm() );
730
- }
731
- }
732
- }
733
- int blue = -1;
734
- QgsContrastEnhancement* blueEnhancement = 0;
735
- if ( mBlueBandName != TRSTRING_NOT_SET )
736
- {
737
- blue = bandNumber( mBlueBandName );
738
- if ( contrastEnhancementAlgorithm() != QgsContrastEnhancement::NoEnhancement )
739
- {
740
- QgsContrastEnhancement* bkBlueEnhancement = contrastEnhancement( blue );
741
- if ( bkBlueEnhancement )
742
- {
743
- blueEnhancement = new QgsContrastEnhancement(( QgsContrastEnhancement::QgsRasterDataType )(
744
- mDataProvider->dataType( blue ) ) );
745
- blueEnhancement->setMinimumValue( bkBlueEnhancement->minimumValue() );
746
- blueEnhancement->setMaximumValue( bkBlueEnhancement->maximumValue() );
747
- blueEnhancement->setContrastEnhancementAlgorithm( contrastEnhancementAlgorithm() );
748
- }
749
- }
750
- }
751
- renderer = new QgsMultiBandColorRenderer( mDataProvider, red, green, blue,
752
- redEnhancement, greenEnhancement, blueEnhancement );
753
- break;
754
- }
755
- case SingleBandColorDataStyle:
756
- {
757
- renderer = new QgsSingleBandColorDataRenderer( mDataProvider, bandNumber( mGrayBandName ) );
758
- break;
759
- }
760
- default:
761
- break;
762
- }
763
-
764
- if ( !renderer )
765
- {
766
- return;
767
- }
768
-
769
- renderer->setOpacity( mTransparencyLevel / 255.0 );
770
-
771
- QgsRasterTransparency* tr = new QgsRasterTransparency(); //renderer takes ownership
772
- if ( mDataProvider->bandCount() == 1 )
773
- {
774
- tr->setTransparentSingleValuePixelList( mRasterTransparency.transparentSingleValuePixelList() );
775
- }
776
- else if ( mDataProvider->bandCount() == 3 )
777
- {
778
- tr->setTransparentThreeValuePixelList( mRasterTransparency.transparentThreeValuePixelList() );
779
- }
780
- renderer->setRasterTransparency( tr );
781
-
782
- if ( mTransparencyBandName != TRSTRING_NOT_SET )
783
- {
784
- int tBand = bandNumber( mTransparencyBandName );
785
- if ( tBand > 0 )
786
- {
787
- renderer->setAlphaBand( tBand );
788
- }
789
- }
790
- renderer->setInvertColor( mInvertColor );
791
- setRenderer( renderer );
792
- #endif // 0
793
598
}
794
599
795
600
/* *
0 commit comments