Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 committed Mar 17, 2011
1 parent bc9e7be commit 2edcfa6
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/analysis/raster/qgsrastercalcnode.cpp
Expand Up @@ -122,6 +122,8 @@ bool QgsRasterCalcNode::calculate( QMap<QString, QgsRasterMatrix*>& rasterData,
break;
case opATAN:
leftMatrix.atangens();
case opSIGN:
leftMatrix.changeSign();
break;
default:
return false;
Expand Down
3 changes: 2 additions & 1 deletion src/analysis/raster/qgsrastercalcnode.h
Expand Up @@ -56,7 +56,8 @@ class ANALYSIS_EXPORT QgsRasterCalcNode
opGE, // >=
opLE, // <=
opAND,
opOR
opOR,
opSIGN //change sign
};

QgsRasterCalcNode();
Expand Down
3 changes: 3 additions & 0 deletions src/analysis/raster/qgsrastercalcparser.yy
Expand Up @@ -70,6 +70,7 @@
%left '+' '-'
%left '*' '/'
%left '^'
%left UMINUS // fictitious symbol (for unary minus)

%%

Expand All @@ -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($$); }
;
Expand Down
7 changes: 7 additions & 0 deletions src/analysis/raster/qgsrastermatrix.cpp
Expand Up @@ -167,6 +167,11 @@ bool QgsRasterMatrix::atangens()
return oneArgumentOperation( opATAN );
}

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

bool QgsRasterMatrix::oneArgumentOperation( OneArgOperator op )
{
if ( !mData )
Expand Down Expand Up @@ -211,6 +216,8 @@ bool QgsRasterMatrix::oneArgumentOperation( OneArgOperator op )
case opATAN:
mData[i] = static_cast<float>( atan( value ) );
break;
case opSIGN:
mData[i] = -value;
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/analysis/raster/qgsrastermatrix.h
Expand Up @@ -48,6 +48,7 @@ class ANALYSIS_EXPORT QgsRasterMatrix
opASIN,
opACOS,
opATAN,
opSIGN
};

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

private:
int mColumns;
Expand Down

0 comments on commit 2edcfa6

Please sign in to comment.