Skip to content
Permalink
Browse files

raster cleanup

  • Loading branch information
blazek committed Apr 16, 2013
1 parent 1208051 commit c000ded9e6b6c541092b67f86f37639ddc56270e
@@ -44,15 +44,11 @@ class QgsRasterInterface
enum Capability
{
NoCapabilities,
Identify,
ExactMinimumMaximum,
ExactResolution,
EstimatedMinimumMaximum,
BuildPyramids,
Histogram,
Size,
Create,
Remove,
BuildPyramids,
Identify,
IdentifyValue,
IdentifyText,
IdentifyHtml,
@@ -195,7 +195,10 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
mOptsPage_Pyramids->setEnabled( false );
}

if ( !( provider->capabilities() & QgsRasterDataProvider::Histogram ) )
// We can calculate histogram for all data sources but estimated only if
// size is unknown - could also be enabled if well supported (estimated histogram
// and and let user know that it is estimated)
if ( !( provider->capabilities() & QgsRasterDataProvider::Size ) )
{
// disable Histogram tab completely
mOptsPage_Histogram->setEnabled( false );
@@ -572,7 +575,7 @@ void QgsRasterLayerProperties::sync()
}
}

if ( !( mRasterLayer->dataProvider()->capabilities() & QgsRasterDataProvider::Histogram ) )
if ( !( mRasterLayer->dataProvider()->capabilities() & QgsRasterDataProvider::Size ) )
{
if ( mOptsPage_Histogram != NULL )
{
@@ -106,7 +106,7 @@ QgsRasterBlock * QgsRasterDataProvider::block( int theBandNo, QgsRectangle cons
double tmpXRes, tmpYRes;
double providerXRes = 0;
double providerYRes = 0;
if ( capabilities() & ExactResolution )
if ( capabilities() & Size )
{
providerXRes = extent().width() / xSize();
providerYRes = extent().height() / ySize();
@@ -230,14 +230,6 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRast
return colorName( colorInterpretation( theBandNo ) );
}

/** Get block size */
//virtual int xBlockSize() const { return 0; }
//virtual int yBlockSize() const { return 0; }

/** Get raster size */
//virtual int xSize() const { return 0; }
//virtual int ySize() const { return 0; }

// TODO: remove or make protected all readBlock working with void*

/** read block of data */
@@ -24,29 +24,21 @@
#include <qmath.h>

#include "qgslogger.h"
#include "qgsrasterinterface.h"
#include "qgsrasterbandstats.h"
#include "qgsrasterhistogram.h"
#include "qgsrasterinterface.h"
#include "qgsrectangle.h"

//#include "cpl_conv.h"

QgsRasterInterface::QgsRasterInterface( QgsRasterInterface * input )
: mInput( input )
, mOn( true )
//, mStatsOn( false )
{
}

QgsRasterInterface::~QgsRasterInterface()
{
}

//bool QgsRasterInterface::isNoDataValue( int bandNo, double value ) const
//{
// return QgsRasterBlock::isNoDataValue( value, noDataValue( bandNo ) );
//}

void QgsRasterInterface::initStatistics( QgsRasterBandStats &theStatistics,
int theBandNo,
int theStats,
@@ -168,8 +160,6 @@ QgsRasterBandStats QgsRasterInterface::bandStatistics( int theBandNo,
int myNXBlocks = ( myWidth + myXBlockSize - 1 ) / myXBlockSize;
int myNYBlocks = ( myHeight + myYBlockSize - 1 ) / myYBlockSize;

// void *myData = qgsMalloc( myXBlockSize * myYBlockSize * ( QgsRasterBlock::typeSize( dataType( theBandNo ) ) ) );

double myXRes = myExtent.width() / myWidth;
double myYRes = myExtent.height() / myHeight;
// TODO: progress signals
@@ -194,20 +184,14 @@ QgsRasterBandStats QgsRasterInterface::bandStatistics( int theBandNo,

QgsRectangle myPartExtent( xmin, ymin, xmax, ymax );

//readBlock( theBandNo, myPartExtent, myBlockWidth, myBlockHeight, myData );
QgsRasterBlock* blk = block( theBandNo, myPartExtent, myBlockWidth, myBlockHeight );

// Collect the histogram counts.
for ( size_t i = 0; i < (( size_t ) myBlockHeight ) * myBlockWidth; i++ )
{
if ( blk->isNoData( i ) )
{
continue; // NULL
}
if ( blk->isNoData( i ) ) continue; // NULL

//double myValue = readValue( myData, myDataType, myX + ( myY * myBlockWidth ) );
double myValue = blk->value( i );
//QgsDebugMsg ( QString ( "%1 %2 value %3" ).arg (myX).arg(myY).arg( myValue ) );

myRasterBandStats.sum += myValue;
myRasterBandStats.elementCount++;
@@ -230,9 +214,6 @@ QgsRasterBandStats QgsRasterInterface::bandStatistics( int theBandNo,
}
}

//myRasterBandStats.sumOfSquares += static_cast < double >
// ( qPow( myValue - myRasterBandStats.mean, 2 ) );

// Single pass stdev
double myDelta = myValue - myMean;
myMean += myDelta / myRasterBandStats.elementCount;
@@ -258,8 +239,6 @@ QgsRasterBandStats QgsRasterInterface::bandStatistics( int theBandNo,
QgsDebugMsg( QString( "MEAN %1" ).arg( myRasterBandStats.mean ) );
QgsDebugMsg( QString( "STDDEV %1" ).arg( myRasterBandStats.stdDev ) );

//qgsFree( myData );

myRasterBandStats.statsGathered = QgsRasterBandStats::All;
mStatistics.append( myRasterBandStats );

@@ -291,7 +270,7 @@ void QgsRasterInterface::initHistogram( QgsRasterHistogram &theHistogram,
}
else
{
// We need statistcs -> avoid histogramDefaults in hasHistogram if possible
// We need statistics -> avoid histogramDefaults in hasHistogram if possible
// TODO: use approximated statistics if aproximated histogram is requested
// (theSampleSize > 0)
QgsRasterBandStats stats = bandStatistics( theBandNo, QgsRasterBandStats::Min, theExtent, theSampleSize );
@@ -431,8 +410,6 @@ QgsRasterHistogram QgsRasterInterface::histogram( int theBandNo,
QgsRectangle myExtent = myHistogram.extent;
myHistogram.histogramVector.resize( myBinCount );

//int myDataType = dataType( theBandNo );

int myXBlockSize = xBlockSize();
int myYBlockSize = yBlockSize();
if ( myXBlockSize == 0 ) // should not happen, but happens
@@ -447,8 +424,6 @@ QgsRasterHistogram QgsRasterInterface::histogram( int theBandNo,
int myNXBlocks = ( myWidth + myXBlockSize - 1 ) / myXBlockSize;
int myNYBlocks = ( myHeight + myYBlockSize - 1 ) / myYBlockSize;

//void *myData = qgsMalloc( myXBlockSize * myYBlockSize * ( QgsRasterBlock::typeSize( dataType( theBandNo ) ) ) );

double myXRes = myExtent.width() / myWidth;
double myYRes = myExtent.height() / myHeight;

@@ -480,7 +455,6 @@ QgsRasterHistogram QgsRasterInterface::histogram( int theBandNo,

QgsRectangle myPartExtent( xmin, ymin, xmax, ymax );

//readBlock( theBandNo, myPartExtent, myBlockWidth, myBlockHeight, myData );
QgsRasterBlock* blk = block( theBandNo, myPartExtent, myBlockWidth, myBlockHeight );

// Collect the histogram counts.
@@ -492,10 +466,7 @@ QgsRasterHistogram QgsRasterInterface::histogram( int theBandNo,
}
double myValue = blk->value( i );

//QgsDebugMsg ( QString ( "%1 %2 value %3" ).arg (myX).arg(myY).arg( myValue ) );

int myBinIndex = static_cast <int>( qFloor(( myValue - myMinimum ) / myBinSize ) ) ;
//QgsDebugMsg( QString( "myValue = %1 myBinIndex = %2" ).arg( myValue ).arg( myBinIndex ) );

if (( myBinIndex < 0 || myBinIndex > ( myBinCount - 1 ) ) && !theIncludeOutOfRange )
{
@@ -510,8 +481,6 @@ QgsRasterHistogram QgsRasterInterface::histogram( int theBandNo,
}
}

//qgsFree( myData );

myHistogram.valid = true;
mHistograms.append( myHistogram );

@@ -572,16 +541,15 @@ QString QgsRasterInterface::capabilitiesString() const

int abilities = capabilities();

// Not all all capabilities are here (Size, IdentifyValue, IdentifyText,
// IdentifyHtml, IdentifyFeature) because those are quite technical and probably
// would be confusing for users

if ( abilities & QgsRasterInterface::Identify )
{
abilitiesList += tr( "Identify" );
}

if ( abilities & QgsRasterInterface::BuildPyramids )
{
abilitiesList += tr( "Build Pyramids" );
}

if ( abilities & QgsRasterInterface::Create )
{
abilitiesList += tr( "Create Datasources" );
@@ -592,77 +560,12 @@ QString QgsRasterInterface::capabilitiesString() const
abilitiesList += tr( "Remove Datasources" );
}

QgsDebugMsg( "Capability: " + abilitiesList.join( ", " ) );

return abilitiesList.join( ", " );
}

#if 0
// version with time counting
void * QgsRasterInterface::block( int bandNo, QgsRectangle const & extent, int width, int height )
{
QTime time;
time.start();

void * b = 0;

if ( !mOn )
{
// Switched off, pass input data unchanged
if ( mInput )
{
b = mInput->block( bandNo, extent, width, height );
}
}
else
{
b = readBlock( bandNo, extent, width, height );
}

if ( mStatsOn )
{
if ( mTime.size() <= bandNo )
{
mTime.resize( bandNo + 1 );
}
// QTime counts only in miliseconds
// We are adding time until next clear, this way the time may be collected
// for the whole QgsRasterLayer::draw() for example, not just for a single part
mTime[bandNo] += time.elapsed();
QgsDebugMsg( QString( "bandNo = %2 time = %3" ).arg( bandNo ).arg( mTime[bandNo] ) );
}
return b;
}
#endif

#if 0
void QgsRasterInterface::setStatsOn( bool on )
{
if ( on )
if ( abilities & QgsRasterInterface::BuildPyramids )
{
mTime.clear();
abilitiesList += tr( "Build Pyramids" );
}
if ( mInput ) mInput->setStatsOn( on );
mStatsOn = on;
}

double QgsRasterInterface::time( bool cumulative )
{
// We can calculate total time only, because we have to subtract time of previous
// interface(s) and we don't know how to assign bands to each other
double t = 0;
for ( int i = 1; i < mTime.size(); i++ )
{
t += mTime[i];
}
if ( cumulative ) return t;
QgsDebugMsg( "Capability: " + abilitiesList.join( ", " ) );

if ( mInput )
{
QgsDebugMsgLevel( QString( "%1 cumulative time = %2 time = %3" ).arg( typeid( *( this ) ).name() ).arg( t ).arg( t - mInput->time( true ) ), 3 );
t -= mInput->time( true );
}
return t;
return abilitiesList.join( ", " );
}
#endif

0 comments on commit c000ded

Please sign in to comment.
You can’t perform that action at this time.