@@ -1872,8 +1872,8 @@ void QgsRasterLayerProperties::refreshHistogram()
1872
1872
// Set axis titles
1873
1873
mpPlot->setAxisTitle ( QwtPlot::xBottom, QObject::tr (" Pixel Value" ) );
1874
1874
mpPlot->setAxisTitle ( QwtPlot::yLeft, QObject::tr (" Frequency" ) );
1875
- mpPlot->setAxisAutoScale ( QwtPlot::xBottom );
1876
1875
mpPlot->setAxisAutoScale ( QwtPlot::yLeft );
1876
+ // x axis scale only set after computing global min/max across bands (see below)
1877
1877
// add a grid
1878
1878
QwtPlotGrid * myGrid = new QwtPlotGrid ();
1879
1879
myGrid->attach (mpPlot);
@@ -1905,6 +1905,9 @@ void QgsRasterLayerProperties::refreshHistogram()
1905
1905
//
1906
1906
// scan through to get counts from layers' histograms
1907
1907
//
1908
+ float myGlobalMin = 0 ;
1909
+ float myGlobalMax = 0 ;
1910
+ bool myFirstIteration = true ;
1908
1911
for ( int myIteratorInt = 1 ;
1909
1912
myIteratorInt <= myBandCountInt;
1910
1913
++myIteratorInt )
@@ -1924,7 +1927,22 @@ void QgsRasterLayerProperties::refreshHistogram()
1924
1927
}
1925
1928
mypCurve->setData (myX2Data,myY2Data);
1926
1929
mypCurve->attach (mpPlot);
1930
+ if ( myFirstIteration || myGlobalMin < myRasterBandStats.minimumValue )
1931
+ {
1932
+ myGlobalMin = myRasterBandStats.minimumValue ;
1933
+ }
1934
+ if ( myFirstIteration || myGlobalMax < myRasterBandStats.maximumValue )
1935
+ {
1936
+ myGlobalMax = myRasterBandStats.maximumValue ;
1937
+ }
1938
+ myFirstIteration = false ;
1927
1939
}
1940
+ // for x axis use band pixel values rather than gdal hist. bin values
1941
+ // subtract -0.5 to prevent rounding errors
1942
+ // see http://www.gdal.org/classGDALRasterBand.html#3f8889607d3b2294f7e0f11181c201c8
1943
+ mpPlot->setAxisScale ( QwtPlot::xBottom,
1944
+ myGlobalMin - 0.5 ,
1945
+ myGlobalMax + 0.5 );
1928
1946
mpPlot->replot ();
1929
1947
disconnect ( mRasterLayer , SIGNAL ( progressUpdate ( int ) ), mHistogramProgress , SLOT ( setValue ( int ) ) );
1930
1948
mHistogramProgress ->hide ();
0 commit comments