Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 committed Nov 4, 2010
1 parent a8b2861 commit 725432b
Show file tree
Hide file tree
Showing 5 changed files with 334 additions and 417 deletions.
25 changes: 13 additions & 12 deletions src/analysis/raster/qgsrastercalcnode.cpp
@@ -1,4 +1,5 @@
#include "qgsrastercalcnode.h"
#include <cfloat>

QgsRasterCalcNode::QgsRasterCalcNode(): mLeft( 0 ), mRight( 0 ), mRasterMatrix( 0 ), mNumber( 0 )
{
Expand All @@ -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;
}
Expand All @@ -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 );
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 725432b

Please sign in to comment.