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;
93 if ( !mLeft || !mLeft->
calculate( rasterData, leftMatrix, row ) )
97 if ( mRight && !mRight->
calculate( rasterData, rightMatrix, row ) )
105 leftMatrix.add( rightMatrix );
108 leftMatrix.subtract( rightMatrix );
111 leftMatrix.multiply( rightMatrix );
114 leftMatrix.divide( rightMatrix );
117 leftMatrix.power( rightMatrix );
120 leftMatrix.equal( rightMatrix );
123 leftMatrix.notEqual( rightMatrix );
126 leftMatrix.greaterThan( rightMatrix );
129 leftMatrix.lesserThan( rightMatrix );
132 leftMatrix.greaterEqual( rightMatrix );
135 leftMatrix.lesserEqual( rightMatrix );
138 leftMatrix.logicalAnd( rightMatrix );
141 leftMatrix.logicalOr( rightMatrix );
144 leftMatrix.min( rightMatrix );
147 leftMatrix.max( rightMatrix );
150 leftMatrix.squareRoot();
156 leftMatrix.cosinus();
159 leftMatrix.tangens();
165 leftMatrix.acosinus();
168 leftMatrix.atangens();
171 leftMatrix.changeSign();
180 leftMatrix.absoluteValue();
185 int newNColumns = leftMatrix.nColumns();
186 int newNRows = leftMatrix.nRows();
187 result.
setData( newNColumns, newNRows, leftMatrix.takeData(), leftMatrix.nodataValue() );
192 size_t nEntries =
static_cast<size_t>( result.
nColumns() * result.
nRows() );
193 std::vector<double> *data =
new std::vector<double>( nEntries );
194 std::fill( std::begin( *data ), std::end( *data ), mNumber );
201 double *data =
new double[nEntries];
202 for (
int i = 0; i < nEntries; ++i )
228 result = QStringLiteral(
"( %1 + %2 )" ).arg( left ).arg( right );
231 result = QStringLiteral(
"( %1 - %2 )" ).arg( left ).arg( right );
234 result = QStringLiteral(
"-%1" ).arg( left );
237 result = QStringLiteral(
"%1 * %2" ).arg( left ).arg( right );
240 result = QStringLiteral(
"%1 / %2" ).arg( left ).arg( right );
244 result = QStringLiteral(
"pow( %1, %2 )" ).arg( left ).arg( right );
246 result = QStringLiteral(
"%1^%2" ).arg( left ).arg( right );
250 result = QStringLiteral(
"( float ) ( %1 == %2 )" ).arg( left ).arg( right );
252 result = QStringLiteral(
"%1 = %2" ).arg( left ).arg( right );
256 result = QStringLiteral(
"( float ) ( %1 != %2 )" ).arg( left ).arg( right );
258 result = QStringLiteral(
"%1 != %2" ).arg( left ).arg( right );
262 result = QStringLiteral(
"( float ) ( %1 > %2 )" ).arg( left ).arg( right );
264 result = QStringLiteral(
"%1 > %2" ).arg( left ).arg( right );
268 result = QStringLiteral(
"( float ) ( %1 < %2" ).arg( left ).arg( right );
270 result = QStringLiteral(
"%1 < %2" ).arg( left ).arg( right );
274 result = QStringLiteral(
"( float ) ( %1 >= %2 )" ).arg( left ).arg( right );
276 result = QStringLiteral(
"%1 >= %2" ).arg( left ).arg( right );
280 result = QStringLiteral(
"( float ) ( %1 <= %2 )" ).arg( left ).arg( right );
282 result = QStringLiteral(
"%1 <= %2" ).arg( left ).arg( right );
286 result = QStringLiteral(
"( float ) ( %1 && %2 )" ).arg( left ).arg( right );
288 result = QStringLiteral(
"%1 AND %2" ).arg( left ).arg( right );
292 result = QStringLiteral(
"( float ) ( %1 || %2 )" ).arg( left ).arg( right );
294 result = QStringLiteral(
"%1 OR %2" ).arg( left ).arg( right );
297 result = QStringLiteral(
"sqrt( %1 )" ).arg( left );
300 result = QStringLiteral(
"sin( %1 )" ).arg( left );
303 result = QStringLiteral(
"cos( %1 )" ).arg( left );
306 result = QStringLiteral(
"tan( %1 )" ).arg( left );
309 result = QStringLiteral(
"asin( %1 )" ).arg( left );
312 result = QStringLiteral(
"acos( %1 )" ).arg( left );
315 result = QStringLiteral(
"atan( %1 )" ).arg( left );
318 result = QStringLiteral(
"log( %1 )" ).arg( left );
321 result = QStringLiteral(
"log10( %1 )" ).arg( left );
325 result = QStringLiteral(
"fabs( %1 )" ).arg( left );
328 result = QStringLiteral(
"abs( %1 )" ).arg( left );
332 result = QStringLiteral(
"min( ( float ) ( %1 ), ( float ) ( %2 ) )" ).arg( left ).arg( right );
334 result = QStringLiteral(
"min( %1, %2 )" ).arg( left ).arg( right );
338 result = QStringLiteral(
"max( ( float ) ( %1 ), ( float ) ( %2 ) )" ).arg( left ).arg( right );
340 result = QStringLiteral(
"max( %1, %2 )" ).arg( left ).arg( right );
347 result = QStringLiteral(
"\"%1\"" ).arg( mRasterName );
350 result = QString::number( mNumber );
353 result = QStringLiteral(
"( float ) ( %1 )" ).arg( result );
364 QList<const QgsRasterCalcNode *> nodeList;
366 nodeList.push_back(
this );
368 nodeList.append( mLeft->
findNodes( type ) );
370 nodeList.append( mRight->
findNodes( type ) );
376 extern QgsRasterCalcNode *localParseRasterCalcString(
const QString & str, QString & parserErrorMsg );
377 return localParseRasterCalcString( str, parserErrorMsg );
double nodataValue() const
bool calculate(QMap< QString, QgsRasterBlock * > &rasterData, QgsRasterMatrix &result, int row=-1) const
Calculates result of raster calculation (might be real matrix or single number).
void setData(int cols, int rows, double *data, double nodataValue)
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.
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.