[QGIS Commit] r14483 - trunk/qgis/src/analysis/raster
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Mon Nov 1 13:47:57 EDT 2010
Author: mhugent
Date: 2010-11-01 10:47:57 -0700 (Mon, 01 Nov 2010)
New Revision: 14483
Modified:
trunk/qgis/src/analysis/raster/qgsrastercalclexer.ll
trunk/qgis/src/analysis/raster/qgsrastercalcnode.cpp
trunk/qgis/src/analysis/raster/qgsrastercalcnode.h
trunk/qgis/src/analysis/raster/qgsrastercalcparser.yy
trunk/qgis/src/analysis/raster/qgsrastermatrix.cpp
trunk/qgis/src/analysis/raster/qgsrastermatrix.h
Log:
Apply patch #3178
Modified: trunk/qgis/src/analysis/raster/qgsrastercalclexer.ll
===================================================================
--- trunk/qgis/src/analysis/raster/qgsrastercalclexer.ll 2010-11-01 16:21:59 UTC (rev 14482)
+++ trunk/qgis/src/analysis/raster/qgsrastercalclexer.ll 2010-11-01 17:47:57 UTC (rev 14483)
@@ -58,8 +58,13 @@
"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]; }
{number} { rasterlval.number = atof(rastertext); return NUMBER; }
Modified: trunk/qgis/src/analysis/raster/qgsrastercalcnode.cpp
===================================================================
--- trunk/qgis/src/analysis/raster/qgsrastercalcnode.cpp 2010-11-01 16:21:59 UTC (rev 14482)
+++ trunk/qgis/src/analysis/raster/qgsrastercalcnode.cpp 2010-11-01 17:47:57 UTC (rev 14483)
@@ -77,6 +77,24 @@
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 @@
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 );
}
Modified: trunk/qgis/src/analysis/raster/qgsrastercalcnode.h
===================================================================
--- trunk/qgis/src/analysis/raster/qgsrastercalcnode.h 2010-11-01 16:21:59 UTC (rev 14482)
+++ trunk/qgis/src/analysis/raster/qgsrastercalcnode.h 2010-11-01 17:47:57 UTC (rev 14483)
@@ -48,7 +48,13 @@
opTAN,
opASIN,
opACOS,
- opATAN
+ opATAN,
+ opEQ, // =
+ opNE, //!=
+ opGT, // >
+ opLT, // <
+ opGE, // >=
+ opLE, // <=
};
QgsRasterCalcNode();
Modified: trunk/qgis/src/analysis/raster/qgsrastercalcparser.yy
===================================================================
--- trunk/qgis/src/analysis/raster/qgsrastercalcparser.yy 2010-11-01 16:21:59 UTC (rev 14482)
+++ trunk/qgis/src/analysis/raster/qgsrastercalcparser.yy 2010-11-01 17:47:57 UTC (rev 14483)
@@ -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 @@
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); }
Modified: trunk/qgis/src/analysis/raster/qgsrastermatrix.cpp
===================================================================
--- trunk/qgis/src/analysis/raster/qgsrastermatrix.cpp 2010-11-01 16:21:59 UTC (rev 14482)
+++ trunk/qgis/src/analysis/raster/qgsrastermatrix.cpp 2010-11-01 17:47:57 UTC (rev 14483)
@@ -93,6 +93,36 @@
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 @@
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 @@
}
}
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 @@
}
}
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 @@
}
}
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;
Modified: trunk/qgis/src/analysis/raster/qgsrastermatrix.h
===================================================================
--- trunk/qgis/src/analysis/raster/qgsrastermatrix.h 2010-11-01 16:21:59 UTC (rev 14482)
+++ trunk/qgis/src/analysis/raster/qgsrastermatrix.h 2010-11-01 17:47:57 UTC (rev 14483)
@@ -29,6 +29,12 @@
opMUL,
opDIV,
opPOW,
+ opEQ, // =
+ opNE, // != resp. <>
+ opGT, // >
+ opLT, // <
+ opGE, // >=
+ opLE, // <=
};
enum OneArgOperator
@@ -39,7 +45,7 @@
opTAN,
opASIN,
opACOS,
- opATAN
+ opATAN,
};
/**Takes ownership of data array*/
@@ -70,6 +76,12 @@
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();
More information about the QGIS-commit
mailing list