Skip to content
Permalink
Browse files

Add support for unary minus in raster calculator. Fixes ticket 3627

git-svn-id: http://svn.osgeo.org/qgis/trunk@15526 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent
mhugent committed Mar 17, 2011
1 parent bc9e7be commit 2edcfa669a90e40f939cdaf2d8ba0a6670657e9d
@@ -122,6 +122,8 @@ bool QgsRasterCalcNode::calculate( QMap<QString, QgsRasterMatrix*>& rasterData,
break;
case opATAN:
leftMatrix.atangens();
case opSIGN:
leftMatrix.changeSign();
break;
default:
return false;
@@ -56,7 +56,8 @@ class ANALYSIS_EXPORT QgsRasterCalcNode
opGE, // >=
opLE, // <=
opAND,
opOR
opOR,
opSIGN //change sign
};

QgsRasterCalcNode();
@@ -70,6 +70,7 @@
%left '+' '-'
%left '*' '/'
%left '^'
%left UMINUS // fictitious symbol (for unary minus)

%%

@@ -92,6 +93,8 @@ raster_exp:
| raster_exp '+' raster_exp { $$ = new QgsRasterCalcNode(QgsRasterCalcNode::opPLUS, $1, $3); joinTmpNodes($$,$1,$3); }
| raster_exp '-' raster_exp { $$ = new QgsRasterCalcNode(QgsRasterCalcNode::opMINUS, $1, $3); joinTmpNodes($$,$1,$3); }
| '(' raster_exp ')' { $$ = $2; }
| '+' raster_exp %prec UMINUS { $$ = $2; }
| '-' raster_exp %prec UMINUS { $$ = new QgsRasterCalcNode( QgsRasterCalcNode::opSIGN, $2, 0 ); joinTmpNodes($$, $2, 0); }
| NUMBER { $$ = new QgsRasterCalcNode($1); addToTmpNodes($$); }
| RASTER_BAND_REF { $$ = new QgsRasterCalcNode(QString::fromUtf8(rastertext)); addToTmpNodes($$); }
;
@@ -167,6 +167,11 @@ bool QgsRasterMatrix::atangens()
return oneArgumentOperation( opATAN );
}

bool QgsRasterMatrix::changeSign()
{
return oneArgumentOperation( opSIGN );
}

bool QgsRasterMatrix::oneArgumentOperation( OneArgOperator op )
{
if ( !mData )
@@ -211,6 +216,8 @@ bool QgsRasterMatrix::oneArgumentOperation( OneArgOperator op )
case opATAN:
mData[i] = static_cast<float>( atan( value ) );
break;
case opSIGN:
mData[i] = -value;
}
}
}
@@ -48,6 +48,7 @@ class ANALYSIS_EXPORT QgsRasterMatrix
opASIN,
opACOS,
opATAN,
opSIGN
};

/**Takes ownership of data array*/
@@ -97,6 +98,7 @@ class ANALYSIS_EXPORT QgsRasterMatrix
bool acosinus();
bool tangens();
bool atangens();
bool changeSign();

private:
int mColumns;

0 comments on commit 2edcfa6

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