41 const QFileInfo fi( mOutputFilePath );
47 auto writer = std::make_unique<QgsRasterFileWriter>( mOutputFilePath );
48 writer->setOutputProviderKey( QStringLiteral(
"gdal" ) );
49 writer->setOutputFormat( outputFormat );
50 writer->setCreationOptions( mCreationOptions );
52 std::unique_ptr<QgsRasterDataProvider> provider( writer->createOneBandRaster(
Qgis::DataType::Float32, mNumColumns, mNumRows, mInterpolationExtent, crs ) );
55 QgsDebugMsgLevel( QStringLiteral(
"Could not create raster output: %1" ).arg( mOutputFilePath ), 2 );
58 if ( !provider->isValid() )
64 provider->setNoDataValue( 1, mNoDataValue );
66 double currentYValue = mInterpolationExtent.yMaximum() - mCellSizeY / 2.0;
68 double interpolatedValue;
70 std::vector<float> float32Row( mNumColumns );
71 const double step = mNumRows > 0 ? 100.0 / mNumRows : 1;
72 for (
int row = 0; row < mNumRows; row++ )
79 currentXValue = mInterpolationExtent.xMinimum() + mCellSizeX / 2.0;
82 for (
int col = 0; col < mNumColumns; col++ )
84 if ( mInterpolator->interpolatePoint( currentXValue, currentYValue, interpolatedValue, feedback ) == 0 )
86 float32Row[col] = interpolatedValue;
90 float32Row[col] = mNoDataValue;
92 currentXValue += mCellSizeX;
95 if ( !provider->writeBlock( &block, 1, 0, row ) )
97 throw QgsProcessingException( QObject::tr(
"Could not write raster block: %1" ).arg( provider->error().summary() ) );
99 currentYValue -= mCellSizeY;
QgsGridFileWriter(QgsInterpolator *interpolator, const QString &outputPath, const QgsRectangle &extent, int nCols, int nRows)
Constructor for QgsGridFileWriter, for the specified interpolator.