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 )
213 auto floatCast = [ ](
const QString s ) -> QString
215 return QStringLiteral(
"(float) ( %1 )" ).arg( s );
224 result = QStringLiteral(
"%1 + %2" ).arg( left ).arg( right );
228 result = QStringLiteral(
"%1 - %2" ).arg( left ).arg( right );
231 result = QStringLiteral(
"%1 * %2" ).arg( left ).arg( right );
234 result = QStringLiteral(
"%1 / %2" ).arg( left ).arg( right );
238 result = QStringLiteral(
"pow( %1, %2 )" ).arg( floatCast( left ) ).arg( floatCast( right ) );
240 result = QStringLiteral(
"%1^%2" ).arg( left ).arg( right );
244 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 );
258 result = QStringLiteral(
"%1 >= %2" ).arg( left ).arg( right );
261 result = QStringLiteral(
"%1 <= %2" ).arg( left ).arg( right );
265 result = QStringLiteral(
"%1 && %2" ).arg( left ).arg( right );
267 result = QStringLiteral(
"%1 AND %2" ).arg( left ).arg( right );
271 result = QStringLiteral(
"%1 || %2" ).arg( left ).arg( right );
273 result = QStringLiteral(
"%1 OR %2" ).arg( left ).arg( right );
277 result = QStringLiteral(
"sqrt( %1 )" ).arg( floatCast( left ) );
279 result = QStringLiteral(
"sqrt( %1 )" ).arg( left );
283 result = QStringLiteral(
"sin( %1 )" ).arg( floatCast( left ) );
285 result = QStringLiteral(
"sin( %1 )" ).arg( left );
289 result = QStringLiteral(
"cos( %1 )" ).arg( floatCast( left ) );
291 result = QStringLiteral(
"cos( %1 )" ).arg( left );
295 result = QStringLiteral(
"tan( %1 )" ).arg( floatCast( left ) );
297 result = QStringLiteral(
"tan( %1 )" ).arg( left );
301 result = QStringLiteral(
"asin( %1 )" ).arg( floatCast( left ) );
303 result = QStringLiteral(
"asin( %1 )" ).arg( left );
307 result = QStringLiteral(
"acos( %1 )" ).arg( floatCast( left ) );
309 result = QStringLiteral(
"acos( %1 )" ).arg( left );
313 result = QStringLiteral(
"atan( %1 )" ).arg( floatCast( left ) );
315 result = QStringLiteral(
"atan( %1 )" ).arg( left );
319 result = QStringLiteral(
"log( %1 )" ).arg( floatCast( left ) );
321 result = QStringLiteral(
"log( %1 )" ).arg( left );
325 result = QStringLiteral(
"log10( %1 )" ).arg( floatCast( left ) );
327 result = QStringLiteral(
"log10( %1 )" ).arg( left );
334 result = QStringLiteral(
"\"%1\"" ).arg( mRasterName );
337 result = QString::number( mNumber );
347 QList<const QgsRasterCalcNode *> nodeList;
349 nodeList.push_back(
this );
351 nodeList.append( mLeft->
findNodes( type ) );
353 nodeList.append( mRight->
findNodes( type ) );
359 extern QgsRasterCalcNode *localParseRasterCalcString(
const QString & str, QString & parserErrorMsg );
360 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)