Skip to content

Commit ebda009

Browse files
author
timlinux
committed
Show actual pixel values on x axis of raster histogram
git-svn-id: http://svn.osgeo.org/qgis/trunk@14381 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 4f4a212 commit ebda009

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/app/qgsrasterlayerproperties.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1872,8 +1872,8 @@ void QgsRasterLayerProperties::refreshHistogram()
18721872
// Set axis titles
18731873
mpPlot->setAxisTitle( QwtPlot::xBottom, QObject::tr("Pixel Value") );
18741874
mpPlot->setAxisTitle( QwtPlot::yLeft, QObject::tr("Frequency") );
1875-
mpPlot->setAxisAutoScale( QwtPlot::xBottom );
18761875
mpPlot->setAxisAutoScale( QwtPlot::yLeft );
1876+
// x axis scale only set after computing global min/max across bands (see below)
18771877
// add a grid
18781878
QwtPlotGrid * myGrid = new QwtPlotGrid();
18791879
myGrid->attach(mpPlot);
@@ -1905,6 +1905,9 @@ void QgsRasterLayerProperties::refreshHistogram()
19051905
//
19061906
// scan through to get counts from layers' histograms
19071907
//
1908+
float myGlobalMin = 0;
1909+
float myGlobalMax = 0;
1910+
bool myFirstIteration = true;
19081911
for ( int myIteratorInt = 1;
19091912
myIteratorInt <= myBandCountInt;
19101913
++myIteratorInt )
@@ -1924,7 +1927,22 @@ void QgsRasterLayerProperties::refreshHistogram()
19241927
}
19251928
mypCurve->setData(myX2Data,myY2Data);
19261929
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;
19271939
}
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 );
19281946
mpPlot->replot();
19291947
disconnect( mRasterLayer, SIGNAL( progressUpdate( int ) ), mHistogramProgress, SLOT( setValue( int ) ) );
19301948
mHistogramProgress->hide();

0 commit comments

Comments
 (0)