29 , mOutputFilePath( outputPath )
30 , mInterpolationExtent( extent )
31 , mNumColumns( nCols )
33 , mCellSizeX( extent.width() / nCols )
34 , mCellSizeY( extent.height() / nRows )
39 const QFileInfo fi( mOutputFilePath );
45 auto writer = std::make_unique<QgsRasterFileWriter>( mOutputFilePath );
46 writer->setOutputProviderKey( QStringLiteral(
"gdal" ) );
47 writer->setOutputFormat( outputFormat );
49 std::unique_ptr<QgsRasterDataProvider> provider( writer->createOneBandRaster(
Qgis::DataType::Float32, mNumColumns, mNumRows, mInterpolationExtent,
crs ) );
52 QgsDebugMsgLevel( QStringLiteral(
"Could not create raster output: %1" ).arg( mOutputFilePath ), 2 );
55 if ( !provider->isValid() )
61 provider->setNoDataValue( 1, -9999 );
63 double currentYValue = mInterpolationExtent.
yMaximum() - mCellSizeY / 2.0;
65 double interpolatedValue;
67 std::vector<float> float32Row( mNumColumns );
68 const double step = mNumRows > 0 ? 100.0 / mNumRows : 1;
69 for (
int row = 0; row < mNumRows; row++ )
76 currentXValue = mInterpolationExtent.
xMinimum() + mCellSizeX / 2.0;
79 for (
int col = 0; col < mNumColumns; col++ )
81 if ( mInterpolator->
interpolatePoint( currentXValue, currentYValue, interpolatedValue, feedback ) == 0 )
83 float32Row[col] = interpolatedValue;
87 float32Row[col] = -9999;
89 currentXValue += mCellSizeX;
92 provider->writeBlock( &block, 1, 0, row );
93 currentYValue -= mCellSizeY;
@ Float32
Thirty two bit floating point (float)
This class represents a coordinate reference system (CRS).
virtual QgsCoordinateReferenceSystem sourceCrs() const =0
Returns the coordinate reference system for features in the source.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
bool isCanceled() const
Tells whether the operation has been canceled already.
void setProgress(double progress)
Sets the current progress for the feedback object.
QgsGridFileWriter(QgsInterpolator *interpolator, const QString &outputPath, const QgsRectangle &extent, int nCols, int nRows)
Constructor for QgsGridFileWriter, for the specified interpolator.
int writeFile(QgsFeedback *feedback=nullptr)
Writes the grid file.
Interface class for interpolations.
virtual int interpolatePoint(double x, double y, double &result, QgsFeedback *feedback=nullptr)=0
Calculates interpolation value for map coordinates x, y.
QList< LayerData > layerData() const
static int typeSize(Qgis::DataType dataType)
Returns the size in bytes for the specified dataType.
void setData(const QByteArray &data, int offset=0)
Rewrite raw pixel data.
static QString driverForExtension(const QString &extension)
Returns the GDAL driver name for a specified file extension.
A rectangle specified with double values.
#define QgsDebugMsgLevel(str, level)
const QgsCoordinateReferenceSystem & crs
A source together with the information about interpolation attribute / z-coordinate interpolation and...
QgsFeatureSource * source
Feature source.