Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
raster calculator: add logarithmic functions
  • Loading branch information
jef-n committed Mar 24, 2015
1 parent 6309dbd commit 7019db8
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/analysis/raster/qgsrastercalclexer.ll
Expand Up @@ -59,6 +59,8 @@ raster_band_ref_quoted \"(\\.|[^"])*\"
"asin" { rasterlval.op = QgsRasterCalcNode::opASIN; return FUNCTION;}
"acos" { rasterlval.op = QgsRasterCalcNode::opACOS; return FUNCTION;}
"atan" { rasterlval.op = QgsRasterCalcNode::opATAN; return FUNCTION;}
"ln" { rasterlval.op = QgsRasterCalcNode::opLOG; return FUNCTION;}
"log10" { rasterlval.op = QgsRasterCalcNode::opLOG10; return FUNCTION;}
"AND" { return AND; }
"OR" { return OR; }
Expand Down
6 changes: 6 additions & 0 deletions src/analysis/raster/qgsrastercalcnode.cpp
Expand Up @@ -163,6 +163,12 @@ bool QgsRasterCalcNode::calculate( QMap<QString, QgsRasterMatrix*>& rasterData,
case opSIGN:
leftMatrix.changeSign();
break;
case opLOG:
leftMatrix.log();
break;
case opLOG10:
leftMatrix.log10();
break;
default:
return false;
}
Expand Down
2 changes: 2 additions & 0 deletions src/analysis/raster/qgsrastercalcnode.h
Expand Up @@ -58,6 +58,8 @@ class ANALYSIS_EXPORT QgsRasterCalcNode
opAND,
opOR,
opSIGN, // change sign
opLOG,
opLOG10,
opNONE,
};

Expand Down
17 changes: 17 additions & 0 deletions src/analysis/raster/qgsrastermatrix.cpp
Expand Up @@ -182,6 +182,16 @@ bool QgsRasterMatrix::changeSign()
return oneArgumentOperation( opSIGN );
}

bool QgsRasterMatrix::log()
{
return oneArgumentOperation( opLOG );
}

bool QgsRasterMatrix::log10()
{
return oneArgumentOperation( opLOG10 );
}

bool QgsRasterMatrix::oneArgumentOperation( OneArgOperator op )
{
if ( !mData )
Expand Down Expand Up @@ -228,6 +238,13 @@ bool QgsRasterMatrix::oneArgumentOperation( OneArgOperator op )
break;
case opSIGN:
mData[i] = static_cast<float>( -value );
break;
case opLOG:
mData[i] = static_cast<float>( ::log( value ) );
break;
case opLOG10:
mData[i] = static_cast<float>( ::log10( value ) );
break;
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/analysis/raster/qgsrastermatrix.h
Expand Up @@ -48,7 +48,9 @@ class ANALYSIS_EXPORT QgsRasterMatrix
opASIN,
opACOS,
opATAN,
opSIGN
opSIGN,
opLOG,
opLOG10,
};

/**Takes ownership of data array*/
Expand Down Expand Up @@ -102,6 +104,8 @@ class ANALYSIS_EXPORT QgsRasterMatrix
bool tangens();
bool atangens();
bool changeSign();
bool log();
bool log10();

private:
int mColumns;
Expand Down

0 comments on commit 7019db8

Please sign in to comment.