Skip to content
Permalink
Browse files

Apply patch #3178

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14483 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent
mhugent committed Nov 1, 2010
1 parent c2af3c7 commit e20d68b4a6214af9fbf987389ce094b1abf73c9b
@@ -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]; }

@@ -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;
@@ -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 );
}

@@ -48,7 +48,13 @@ class ANALYSIS_EXPORT QgsRasterCalcNode
opTAN,
opASIN,
opACOS,
opATAN
opATAN,
opEQ, // =
opNE, //!=
opGT, // >
opLT, // <
opGE, // >=
opLE, // <=
};

QgsRasterCalcNode();
@@ -55,6 +55,11 @@
%type <node> root
%type <node> raster_exp

%left NE
%left GE
%left LE

%left '=' '<' '>'
%left '+' '-'
%left '*' '/'
%left '^'
@@ -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); }
@@ -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 )
@@ -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;
}
@@ -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;
}
@@ -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;
@@ -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;
@@ -29,6 +29,12 @@ class ANALYSIS_EXPORT QgsRasterMatrix
opMUL,
opDIV,
opPOW,
opEQ, // =
opNE, // != resp. <>
opGT, // >
opLT, // <
opGE, // >=
opLE, // <=
};

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

/**Takes ownership of data array*/
@@ -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();

0 comments on commit e20d68b

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