41 , mRasterName( rasterName )
43 if ( mRasterName.startsWith(
'"' ) && mRasterName.endsWith(
'"' ) )
44 mRasterName = mRasterName.mid( 1, mRasterName.size() - 2 );
60 QMap<QString, QgsRasterBlock *>::iterator it = rasterData.find( mRasterName );
61 if ( it == rasterData.end() )
66 int nRows = ( row >= 0 ? 1 : ( *it )->height() );
67 int startRow = ( row >= 0 ? row : 0 );
68 int endRow = startRow + nRows;
69 int nCols = ( *it )->width();
70 int nEntries = nCols * nRows;
71 double *data =
new double[nEntries];
76 bool isNoData =
false;
77 for (
int dataRow = startRow; dataRow < endRow ; ++dataRow, ++outRow )
79 for (
int dataCol = 0; dataCol < nCols; ++dataCol )
81 const double value = ( *it )->valueAndNoData( dataRow, dataCol, isNoData );
82 data[ dataCol + nCols * outRow] = isNoData ? result.
nodataValue() : value;
94 if ( !mLeft || !mLeft->
calculate( rasterData, leftMatrix, row ) )
98 if ( mRight && !mRight->
calculate( rasterData, rightMatrix, row ) )
106 leftMatrix.
add( rightMatrix );
115 leftMatrix.
divide( rightMatrix );
118 leftMatrix.
power( rightMatrix );
121 leftMatrix.
equal( rightMatrix );
177 int newNColumns = leftMatrix.
nColumns();
178 int newNRows = leftMatrix.
nRows();
184 double *data =
new double[1];
192 double *data =
new double[nEntries];
193 for (
int i = 0; i < nEntries; ++i )
219 result = QStringLiteral(
"( %1 + %2 )" ).arg( left ).arg( right );
223 result = QStringLiteral(
"( %1 - %2 )" ).arg( left ).arg( right );
226 result = QStringLiteral(
"%1 * %2" ).arg( left ).arg( right );
229 result = QStringLiteral(
"%1 / %2" ).arg( left ).arg( right );
233 result = QStringLiteral(
"pow( %1, %2 )" ).arg( left ).arg( right );
235 result = QStringLiteral(
"%1^%2" ).arg( left ).arg( right );
239 result = QStringLiteral(
"%1 == %2" ).arg( left ).arg( right );
241 result = QStringLiteral(
"%1 = %2" ).arg( left ).arg( right );
244 result = QStringLiteral(
"%1 != %2" ).arg( left ).arg( right );
247 result = QStringLiteral(
"%1 > %2" ).arg( left ).arg( right );
250 result = QStringLiteral(
"%1 < %2" ).arg( left ).arg( right );
253 result = QStringLiteral(
"%1 >= %2" ).arg( left ).arg( right );
256 result = QStringLiteral(
"%1 <= %2" ).arg( left ).arg( right );
260 result = QStringLiteral(
"%1 && %2" ).arg( left ).arg( right );
262 result = QStringLiteral(
"%1 AND %2" ).arg( left ).arg( right );
266 result = QStringLiteral(
"%1 || %2" ).arg( left ).arg( right );
268 result = QStringLiteral(
"%1 OR %2" ).arg( left ).arg( right );
271 result = QStringLiteral(
"sqrt( %1 )" ).arg( left );
274 result = QStringLiteral(
"sin( %1 )" ).arg( left );
277 result = QStringLiteral(
"cos( %1 )" ).arg( left );
280 result = QStringLiteral(
"tan( %1 )" ).arg( left );
283 result = QStringLiteral(
"asin( %1 )" ).arg( left );
286 result = QStringLiteral(
"acos( %1 )" ).arg( left );
289 result = QStringLiteral(
"atan( %1 )" ).arg( left );
292 result = QStringLiteral(
"log( %1 )" ).arg( left );
295 result = QStringLiteral(
"log10( %1 )" ).arg( left );
302 result = QStringLiteral(
"\"%1\"" ).arg( mRasterName );
305 result = QString::number( mNumber );
308 result = QStringLiteral(
"(float) ( %1 )" ).arg( result );
319 QList<const QgsRasterCalcNode *> nodeList;
321 nodeList.push_back(
this );
323 nodeList.append( mLeft->
findNodes( type ) );
325 nodeList.append( mRight->
findNodes( type ) );
331 extern QgsRasterCalcNode *localParseRasterCalcString(
const QString & str, QString & parserErrorMsg );
332 return localParseRasterCalcString( str, parserErrorMsg );
double * takeData()
Returns data and ownership.
bool add(const QgsRasterMatrix &other)
Adds another matrix to this one.
void setNodataValue(double d)
double nodataValue() const
bool power(const QgsRasterMatrix &other)
bool greaterThan(const QgsRasterMatrix &other)
bool notEqual(const QgsRasterMatrix &other)
bool equal(const QgsRasterMatrix &other)
bool calculate(QMap< QString, QgsRasterBlock * > &rasterData, QgsRasterMatrix &result, int row=-1) const
Calculates result of raster calculation (might be real matrix or single number).
bool logicalOr(const QgsRasterMatrix &other)
void setData(int cols, int rows, double *data, double nodataValue)
bool subtract(const QgsRasterMatrix &other)
Subtracts another matrix from this one.
QList< const QgsRasterCalcNode * > findNodes(const QgsRasterCalcNode::Type type) const
Returns a list of nodes of a specific type.
Type
defines possible types of node
Operator
possible operators
QgsRasterCalcNode()=default
Constructor for QgsRasterCalcNode.
bool multiply(const QgsRasterMatrix &other)
bool lesserEqual(const QgsRasterMatrix &other)
bool divide(const QgsRasterMatrix &other)
bool greaterEqual(const QgsRasterMatrix &other)
double * data()
Returns data array (but not ownership)
static QgsRasterCalcNode * parseRasterCalcString(const QString &str, QString &parserErrorMsg)
QString toString(bool cStyle=false) const
Returns a string representation of the expression.
bool lesserThan(const QgsRasterMatrix &other)
bool logicalAnd(const QgsRasterMatrix &other)