Skip to content
Permalink
Browse files

raster calculator: add logarithmic functions

  • Loading branch information
jef-n committed Mar 24, 2015
1 parent 6309dbd commit 7019db88315d13361554a26c46a14fefed568936
@@ -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; }
@@ -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;
}
@@ -58,6 +58,8 @@ class ANALYSIS_EXPORT QgsRasterCalcNode
opAND,
opOR,
opSIGN, // change sign
opLOG,
opLOG10,
opNONE,
};

@@ -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 )
@@ -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;
}
}
}
@@ -48,7 +48,9 @@ class ANALYSIS_EXPORT QgsRasterMatrix
opASIN,
opACOS,
opATAN,
opSIGN
opSIGN,
opLOG,
opLOG10,
};

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

private:
int mColumns;

0 comments on commit 7019db8

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