43 , mRasterName( rasterName )
45 if ( mRasterName.startsWith(
'"' ) && mRasterName.endsWith(
'"' ) )
46 mRasterName = mRasterName.mid( 1, mRasterName.size() - 2 );
62 QMap<QString, QgsRasterBlock *>::iterator it = rasterData.find( mRasterName );
63 if ( it == rasterData.end() )
68 int nRows = ( row >= 0 ? 1 : ( *it )->height() );
69 int startRow = ( row >= 0 ? row : 0 );
70 int endRow = startRow + nRows;
71 int nCols = ( *it )->width();
72 int nEntries = nCols * nRows;
73 double *data =
new double[nEntries];
78 for (
int dataRow = startRow; dataRow < endRow ; ++dataRow, ++outRow )
80 for (
int dataCol = 0; dataCol < nCols; ++dataCol )
82 data[ dataCol + nCols * outRow] = ( *it )->isNoData( dataRow, dataCol ) ? result.
nodataValue() : ( *it )->value( dataRow, dataCol );
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 )
218 result = QStringLiteral(
"%1 + %2" ).arg( left ).arg( right );
222 result = QStringLiteral(
"%1 - %2" ).arg( left ).arg( right );
225 result = QStringLiteral(
"%1 * %2" ).arg( left ).arg( right );
228 result = QStringLiteral(
"%1 / %2" ).arg( left ).arg( right );
232 result = QStringLiteral(
"pow( %1, %2 )" ).arg( left ).arg( right );
234 result = QStringLiteral(
"%1^%2" ).arg( left ).arg( right );
238 result = QStringLiteral(
"%1 == %2" ).arg( left ).arg( right );
240 result = QStringLiteral(
"%1 = %2" ).arg( left ).arg( right );
243 result = QStringLiteral(
"%1 != %2" ).arg( left ).arg( right );
246 result = QStringLiteral(
"%1 > %2" ).arg( left ).arg( right );
249 result = QStringLiteral(
"%1 < %2" ).arg( left ).arg( right );
252 result = QStringLiteral(
"%1 >= %2" ).arg( left ).arg( right );
255 result = QStringLiteral(
"%1 <= %2" ).arg( left ).arg( right );
259 result = QStringLiteral(
"%1 && %2" ).arg( left ).arg( right );
261 result = QStringLiteral(
"%1 AND %2" ).arg( left ).arg( right );
265 result = QStringLiteral(
"%1 || %2" ).arg( left ).arg( right );
267 result = QStringLiteral(
"%1 OR %2" ).arg( left ).arg( right );
270 result = QStringLiteral(
"sqrt( %1 )" ).arg( left );
273 result = QStringLiteral(
"sin( %1 )" ).arg( left );
276 result = QStringLiteral(
"cos( %1 )" ).arg( left );
279 result = QStringLiteral(
"tan( %1 )" ).arg( left );
282 result = QStringLiteral(
"asin( %1 )" ).arg( left );
285 result = QStringLiteral(
"acos( %1 )" ).arg( left );
288 result = QStringLiteral(
"atan( %1 )" ).arg( left );
291 result = QStringLiteral(
"log( %1 )" ).arg( left );
294 result = QStringLiteral(
"log10( %1 )" ).arg( left );
301 result = QStringLiteral(
"\"%1\"" ).arg( mRasterName );
304 result = QString::number( mNumber );
314 QList<const QgsRasterCalcNode *> nodeList;
316 nodeList.push_back(
this );
318 nodeList.append( mLeft->
findNodes( type ) );
320 nodeList.append( mRight->
findNodes( type ) );
326 extern QgsRasterCalcNode *localParseRasterCalcString(
const QString & str, QString & parserErrorMsg );
327 return localParseRasterCalcString( str, parserErrorMsg );
double * takeData()
Returns data and ownership.
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 add(const QgsRasterMatrix &other)
Adds another matrix to this one.
void setNodataValue(double d)
bool power(const QgsRasterMatrix &other)
QList< const QgsRasterCalcNode * > findNodes(const QgsRasterCalcNode::Type type) const
Returns a list of nodes of a specific type.
bool greaterThan(const QgsRasterMatrix &other)
QString toString(bool cStyle=false) const
Returns a string representation of the expression.
bool notEqual(const QgsRasterMatrix &other)
bool equal(const QgsRasterMatrix &other)
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.
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)
double nodataValue() const
bool greaterEqual(const QgsRasterMatrix &other)
double * data()
Returns data array (but not ownership)
static QgsRasterCalcNode * parseRasterCalcString(const QString &str, QString &parserErrorMsg)
bool lesserThan(const QgsRasterMatrix &other)
bool logicalAnd(const QgsRasterMatrix &other)