Skip to content

Commit

Permalink
Show actual pixel values on x axis of raster histogram
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14381 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux committed Oct 15, 2010
1 parent b859ba9 commit ef4f7ff
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/app/qgsrasterlayerproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1872,8 +1872,8 @@ void QgsRasterLayerProperties::refreshHistogram()
// Set axis titles
mpPlot->setAxisTitle( QwtPlot::xBottom, QObject::tr("Pixel Value") );
mpPlot->setAxisTitle( QwtPlot::yLeft, QObject::tr("Frequency") );
mpPlot->setAxisAutoScale( QwtPlot::xBottom );
mpPlot->setAxisAutoScale( QwtPlot::yLeft );
// x axis scale only set after computing global min/max across bands (see below)
// add a grid
QwtPlotGrid * myGrid = new QwtPlotGrid();
myGrid->attach(mpPlot);
Expand Down Expand Up @@ -1905,6 +1905,9 @@ void QgsRasterLayerProperties::refreshHistogram()
//
// scan through to get counts from layers' histograms
//
float myGlobalMin = 0;
float myGlobalMax = 0;
bool myFirstIteration = true;
for ( int myIteratorInt = 1;
myIteratorInt <= myBandCountInt;
++myIteratorInt )
Expand All @@ -1924,7 +1927,22 @@ void QgsRasterLayerProperties::refreshHistogram()
}
mypCurve->setData(myX2Data,myY2Data);
mypCurve->attach(mpPlot);
if ( myFirstIteration || myGlobalMin < myRasterBandStats.minimumValue )
{
myGlobalMin = myRasterBandStats.minimumValue;
}
if ( myFirstIteration || myGlobalMax < myRasterBandStats.maximumValue )
{
myGlobalMax = myRasterBandStats.maximumValue;
}
myFirstIteration = false;
}
// for x axis use band pixel values rather than gdal hist. bin values
// subtract -0.5 to prevent rounding errors
// see http://www.gdal.org/classGDALRasterBand.html#3f8889607d3b2294f7e0f11181c201c8
mpPlot->setAxisScale ( QwtPlot::xBottom,
myGlobalMin - 0.5,
myGlobalMax + 0.5 );
mpPlot->replot();
disconnect( mRasterLayer, SIGNAL( progressUpdate( int ) ), mHistogramProgress, SLOT( setValue( int ) ) );
mHistogramProgress->hide();
Expand Down

0 comments on commit ef4f7ff

Please sign in to comment.