Skip to content
Permalink
Browse files

Fix consideration of nodata values in raster calculator, code cleanups

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14503 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent
mhugent committed Nov 4, 2010
1 parent a8b2861 commit 725432bb19c3343f6185f27bef25bcbb68aa05a1
@@ -1,4 +1,5 @@
#include "qgsrastercalcnode.h"
#include <cfloat>

QgsRasterCalcNode::QgsRasterCalcNode(): mLeft( 0 ), mRight( 0 ), mRasterMatrix( 0 ), mNumber( 0 )
{
@@ -18,11 +19,11 @@ QgsRasterCalcNode::QgsRasterCalcNode( const QString& rasterName ): mType( tRaste

QgsRasterCalcNode::~QgsRasterCalcNode()
{
if ( mLeft )
if( mLeft )
{
delete mLeft;
}
if ( mRight )
if( mRight )
{
delete mRight;
}
@@ -33,34 +34,34 @@ bool QgsRasterCalcNode::calculate( QMap<QString, QgsRasterMatrix*>& rasterData,
//if type is raster ref: return a copy of the corresponding matrix

//if type is operator, call the proper matrix operations
if ( mType == tRasterRef )
if( mType == tRasterRef )
{
QMap<QString, QgsRasterMatrix*>::iterator it = rasterData.find( mRasterName );
if ( it == rasterData.end() )
if( it == rasterData.end() )
{
return false;
}

int nEntries = ( *it )->nColumns() * ( *it )->nRows();
float* data = new float[nEntries];
memcpy( data, ( *it )->data(), nEntries * sizeof( float ) );
result.setData(( *it )->nColumns(), ( *it )->nRows(), data );
result.setData(( *it )->nColumns(), ( *it )->nRows(), data, ( *it )->nodataValue() );
return true;
}
else if ( mType == tOperator )
else if( mType == tOperator )
{
QgsRasterMatrix leftMatrix, rightMatrix;
QgsRasterMatrix resultMatrix;
if ( !mLeft || !mLeft->calculate( rasterData, leftMatrix ) )
if( !mLeft || !mLeft->calculate( rasterData, leftMatrix ) )
{
return false;
}
if ( mRight && !mRight->calculate( rasterData, rightMatrix ) )
if( mRight && !mRight->calculate( rasterData, rightMatrix ) )
{
return false;
}

switch ( mOperator )
switch( mOperator )
{
case opPLUS:
leftMatrix.add( rightMatrix );
@@ -121,14 +122,14 @@ bool QgsRasterCalcNode::calculate( QMap<QString, QgsRasterMatrix*>& rasterData,
}
int newNColumns = leftMatrix.nColumns();
int newNRows = leftMatrix.nRows();
result.setData( newNColumns, newNRows, leftMatrix.takeData() );
result.setData( newNColumns, newNRows, leftMatrix.takeData(), leftMatrix.nodataValue() );
return true;
}
else if ( mType == tNumber )
else if( mType == tNumber )
{
float* data = new float[1];
data[0] = mNumber;
result.setData( 1, 1, data );
result.setData( 1, 1, data, -FLT_MAX );
return true;
}
return false;

0 comments on commit 725432b

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