Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Apply patch #3178
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14483 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Nov 1, 2010
1 parent c2af3c7 commit e20d68b
Show file tree
Hide file tree
Showing 6 changed files with 213 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/analysis/raster/qgsrastercalclexer.ll
Expand Up @@ -58,7 +58,12 @@ raster_band_ref ({raster_ref_char}+)@{dig}
"acos" { rasterlval.op = QgsRasterCalcNode::opACOS; return FUNCTION;}
"atan" { rasterlval.op = QgsRasterCalcNode::opATAN; return FUNCTION;}

[+-/*^] { return yytext[0]; }
"!=" { return NE; }
"<=" { return LE; }
">=" { return GE; }

[=><+-/*^] { return yytext[0]; }


[()] { return yytext[0]; }

Expand Down
20 changes: 19 additions & 1 deletion src/analysis/raster/qgsrastercalcnode.cpp
Expand Up @@ -77,6 +77,24 @@ bool QgsRasterCalcNode::calculate( QMap<QString, QgsRasterMatrix*>& rasterData,
case opPOW:
leftMatrix.power( rightMatrix );
break;
case opEQ:
leftMatrix.equal( rightMatrix );
break;
case opNE:
leftMatrix.notEqual( rightMatrix );
break;
case opGT:
leftMatrix.greaterThan( rightMatrix );
break;
case opLT:
leftMatrix.lesserThan( rightMatrix );
break;
case opGE:
leftMatrix.greaterEqual( rightMatrix );
break;
case opLE:
leftMatrix.lesserEqual( rightMatrix );
break;
case opSQRT:
leftMatrix.squareRoot();
break;
Expand Down Expand Up @@ -118,7 +136,7 @@ bool QgsRasterCalcNode::calculate( QMap<QString, QgsRasterMatrix*>& rasterData,

QgsRasterCalcNode* QgsRasterCalcNode::parseRasterCalcString( const QString& str, QString& parserErrorMsg )
{
extern QgsRasterCalcNode* localParseRasterCalcString( const QString& str, QString& parserErrorMsg );
extern QgsRasterCalcNode* localParseRasterCalcString( const QString & str, QString & parserErrorMsg );
return localParseRasterCalcString( str, parserErrorMsg );
}

8 changes: 7 additions & 1 deletion src/analysis/raster/qgsrastercalcnode.h
Expand Up @@ -48,7 +48,13 @@ class ANALYSIS_EXPORT QgsRasterCalcNode
opTAN,
opASIN,
opACOS,
opATAN
opATAN,
opEQ, // =
opNE, //!=
opGT, // >
opLT, // <
opGE, // >=
opLE, // <=
};

QgsRasterCalcNode();
Expand Down
11 changes: 11 additions & 0 deletions src/analysis/raster/qgsrastercalcparser.yy
Expand Up @@ -55,6 +55,11 @@
%type <node> root
%type <node> raster_exp

%left NE
%left GE
%left LE

%left '=' '<' '>'
%left '+' '-'
%left '*' '/'
%left '^'
Expand All @@ -66,6 +71,12 @@ root: raster_exp{}

raster_exp:
FUNCTION '(' raster_exp ')' { $$ = new QgsRasterCalcNode($1, $3, 0); joinTmpNodes($$, $3, 0);}
| raster_exp '=' raster_exp { $$ = new QgsRasterCalcNode( QgsRasterCalcNode::opEQ, $1, $3 ); joinTmpNodes($$,$1,$3); }
| raster_exp NE raster_exp { $$ = new QgsRasterCalcNode( QgsRasterCalcNode::opNE, $1, $3 ); joinTmpNodes($$,$1,$3); }
| raster_exp '>' raster_exp { $$ = new QgsRasterCalcNode( QgsRasterCalcNode::opGT, $1, $3 ); joinTmpNodes($$, $1, $3); }
| raster_exp '<' raster_exp { $$ = new QgsRasterCalcNode( QgsRasterCalcNode::opLT, $1, $3 ); joinTmpNodes($$, $1, $3); }
| raster_exp GE raster_exp { $$ = new QgsRasterCalcNode( QgsRasterCalcNode::opGE, $1, $3 ); joinTmpNodes($$, $1, $3); }
| raster_exp LE raster_exp { $$ = new QgsRasterCalcNode( QgsRasterCalcNode::opLE, $1, $3 ); joinTmpNodes($$, $1, $3); }
| raster_exp '^' raster_exp { $$ = new QgsRasterCalcNode(QgsRasterCalcNode::opPOW, $1, $3); joinTmpNodes($$,$1,$3); }
| raster_exp '*' raster_exp { $$ = new QgsRasterCalcNode(QgsRasterCalcNode::opMUL, $1, $3); joinTmpNodes($$,$1,$3); }
| raster_exp '/' raster_exp { $$ = new QgsRasterCalcNode(QgsRasterCalcNode::opDIV, $1, $3); joinTmpNodes($$,$1,$3); }
Expand Down
158 changes: 157 additions & 1 deletion src/analysis/raster/qgsrastermatrix.cpp
Expand Up @@ -93,6 +93,36 @@ bool QgsRasterMatrix::power( const QgsRasterMatrix& other )
return twoArgumentOperation( opPOW, other );
}

bool QgsRasterMatrix::equal( const QgsRasterMatrix& other )
{
return twoArgumentOperation( opEQ, other );
}

bool QgsRasterMatrix::notEqual( const QgsRasterMatrix& other )
{
return twoArgumentOperation( opNE, other );
}

bool QgsRasterMatrix::greaterThan( const QgsRasterMatrix& other )
{
return twoArgumentOperation( opGT, other );
}

bool QgsRasterMatrix::lesserThan( const QgsRasterMatrix& other )
{
return twoArgumentOperation( opLT, other );
}

bool QgsRasterMatrix::greaterEqual( const QgsRasterMatrix& other )
{
return twoArgumentOperation( opGE, other );
}

bool QgsRasterMatrix::lesserEqual( const QgsRasterMatrix& other )
{
return twoArgumentOperation( opLE, other );
}

bool QgsRasterMatrix::squareRoot()
{
if ( !mData )
Expand Down Expand Up @@ -241,6 +271,24 @@ bool QgsRasterMatrix::twoArgumentOperation( TwoArgOperator op, const QgsRasterMa
mData[0] = pow( mData[0], ( float ) other.number() );
}
break;
case opEQ:
mData[0] = ( mData[0] == other.number() ? 1 : 0 );
break;
case opNE:
mData[0] = ( mData[0] == other.number() ? 0 : 1 );
break;
case opGT:
mData[0] = ( mData[0] > other.number() ? 1 : 0 );
break;
case opLT:
mData[0] = ( mData[0] < other.number() ? 1 : 0 );
break;
case opGE:
mData[0] = ( mData[0] >= other.number() ? 1 : 0 );
break;
case opLE:
mData[0] = ( mData[0] <= other.number() ? 1 : 0 );
break;
}
return true;
}
Expand Down Expand Up @@ -295,6 +343,42 @@ bool QgsRasterMatrix::twoArgumentOperation( TwoArgOperator op, const QgsRasterMa
}
}
break;
case opEQ:
for ( int i = 0; i < nEntries; ++i )
{
mData[i] = ( mData[i] == matrix[i] ? 1 : 0 );
}
break;
case opNE:
for ( int i = 0; i < nEntries; ++i )
{
mData[i] = ( mData[i] == matrix[i] ? 0 : 1 );
}
break;
case opGT:
for ( int i = 0; i < nEntries; ++i )
{
mData[i] = ( mData[i] > matrix[i] ? 1 : 0 );
}
break;
case opLT:
for ( int i = 0; i < nEntries; ++i )
{
mData[i] = ( mData[i] < matrix[i] ? 1 : 0 );
}
break;
case opGE:
for ( int i = 0; i < nEntries; ++i )
{
mData[i] = ( mData[i] >= matrix[i] ? 1 : 0 );
}
break;
case opLE:
for ( int i = 0; i < nEntries; ++i )
{
mData[i] = ( mData[i] <= matrix[i] ? 1 : 0 );
}
break;
}
return true;
}
Expand Down Expand Up @@ -353,9 +437,45 @@ bool QgsRasterMatrix::twoArgumentOperation( TwoArgOperator op, const QgsRasterMa
}
}
break;
case opEQ:
for ( int i = 0; i < nEntries; ++i )
{
mData[i] = ( value == matrix[i] ? 1 : 0 );
}
break;
case opNE:
for ( int i = 0; i < nEntries; ++i )
{
mData[i] = ( value == matrix[i] ? 0 : 1 );
}
break;
case opGT:
for ( int i = 0; i < nEntries; ++i )
{
mData[i] = ( value > matrix[i] ? 1 : 0 );
}
break;
case opLT:
for ( int i = 0; i < nEntries; ++i )
{
mData[i] = ( value < matrix[i] ? 1 : 0 );
}
break;
case opGE:
for ( int i = 0; i < nEntries; ++i )
{
mData[i] = ( value >= matrix[i] ? 1 : 0 );
}
break;
case opLE:
for ( int i = 0; i < nEntries; ++i )
{
mData[i] = ( value <= matrix[i] ? 1 : 0 );
}
break;
}
}
else
else //this matrix is a real matrix and the other a number
{
value = other.number();
int nEntries = mColumns * mRows;
Expand Down Expand Up @@ -408,6 +528,42 @@ bool QgsRasterMatrix::twoArgumentOperation( TwoArgOperator op, const QgsRasterMa
}
}
break;
case opEQ:
for ( int i = 0; i < nEntries; ++i )
{
mData[i] = ( mData[i] == value ? 1 : 0 );
}
break;
case opNE:
for ( int i = 0; i < nEntries; ++i )
{
mData[i] = ( mData[i] == value ? 0 : 1 );
}
break;
case opGT:
for ( int i = 0; i < nEntries; ++i )
{
mData[i] = ( mData[i] > value ? 1 : 0 );
}
break;
case opLT:
for ( int i = 0; i < nEntries; ++i )
{
mData[i] = ( mData[i] < value ? 1 : 0 );
}
break;
case opGE:
for ( int i = 0; i < nEntries; ++i )
{
mData[i] = ( mData[i] >= value ? 1 : 0 );
}
break;
case opLE:
for ( int i = 0; i < nEntries; ++i )
{
mData[i] = ( mData[i] <= value ? 1 : 0 );
}
break;
}
}
return true;
Expand Down
14 changes: 13 additions & 1 deletion src/analysis/raster/qgsrastermatrix.h
Expand Up @@ -29,6 +29,12 @@ class ANALYSIS_EXPORT QgsRasterMatrix
opMUL,
opDIV,
opPOW,
opEQ, // =
opNE, // != resp. <>
opGT, // >
opLT, // <
opGE, // >=
opLE, // <=
};

enum OneArgOperator
Expand All @@ -39,7 +45,7 @@ class ANALYSIS_EXPORT QgsRasterMatrix
opTAN,
opASIN,
opACOS,
opATAN
opATAN,
};

/**Takes ownership of data array*/
Expand Down Expand Up @@ -70,6 +76,12 @@ class ANALYSIS_EXPORT QgsRasterMatrix
bool multiply( const QgsRasterMatrix& other );
bool divide( const QgsRasterMatrix& other );
bool power( const QgsRasterMatrix& other );
bool equal( const QgsRasterMatrix& other );
bool notEqual( const QgsRasterMatrix& other );
bool greaterThan( const QgsRasterMatrix& other );
bool lesserThan( const QgsRasterMatrix& other );
bool greaterEqual( const QgsRasterMatrix& other );
bool lesserEqual( const QgsRasterMatrix& other );

bool squareRoot();
bool sinus();
Expand Down

0 comments on commit e20d68b

Please sign in to comment.