27 , mOutputFilePath( outputPath )
28 , mInterpolationExtent( extent )
29 , mNumColumns( nCols )
31 , mCellSizeX( extent.width() / nCols )
32 , mCellSizeY( extent.height() / nRows )
37 QFile outputFile( mOutputFilePath );
39 if ( !outputFile.open( QFile::WriteOnly | QIODevice::Truncate ) )
50 QTextStream outStream( &outputFile );
51 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
52 outStream.setCodec(
"UTF-8" );
54 outStream.setRealNumberPrecision( 8 );
55 writeHeader( outStream );
57 double currentYValue = mInterpolationExtent.
yMaximum() - mCellSizeY / 2.0;
59 double interpolatedValue;
61 for (
int i = 0; i < mNumRows; ++i )
63 currentXValue = mInterpolationExtent.
xMinimum() + mCellSizeX / 2.0;
64 for (
int j = 0; j < mNumColumns; ++j )
66 if ( mInterpolator->
interpolatePoint( currentXValue, currentYValue, interpolatedValue, feedback ) == 0 )
68 outStream << interpolatedValue <<
' ';
72 outStream <<
"-9999 ";
74 currentXValue += mCellSizeX;
76 #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
79 outStream << Qt::endl;
81 currentYValue -= mCellSizeY;
90 feedback->
setProgress( 100.0 * i /
static_cast< double >( mNumRows ) );
99 const QFileInfo fi( mOutputFilePath );
100 const QString fileName = fi.absolutePath() +
'/' + fi.completeBaseName() +
".prj";
101 QFile prjFile( fileName );
102 if ( !prjFile.open( QFile::WriteOnly | QIODevice::Truncate ) )
106 QTextStream prjStream( &prjFile );
108 #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
111 prjStream << Qt::endl;
118 int QgsGridFileWriter::writeHeader( QTextStream &outStream )
120 #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
121 outStream <<
"NCOLS " << mNumColumns << endl;
122 outStream <<
"NROWS " << mNumRows << endl;
123 outStream <<
"XLLCORNER " << mInterpolationExtent.
xMinimum() << endl;
124 outStream <<
"YLLCORNER " << mInterpolationExtent.
yMinimum() << endl;
126 outStream <<
"NCOLS " << mNumColumns << Qt::endl;
127 outStream <<
"NROWS " << mNumRows << Qt::endl;
128 outStream <<
"XLLCORNER " << mInterpolationExtent.
xMinimum() << Qt::endl;
129 outStream <<
"YLLCORNER " << mInterpolationExtent.
yMinimum() << Qt::endl;
131 if ( mCellSizeX == mCellSizeY )
133 #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
134 outStream <<
"CELLSIZE " << mCellSizeX << endl;
136 outStream <<
"CELLSIZE " << mCellSizeX << Qt::endl;
141 #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
142 outStream <<
"DX " << mCellSizeX << endl;
143 outStream <<
"DY " << mCellSizeY << endl;
145 outStream <<
"DX " << mCellSizeX << Qt::endl;
146 outStream <<
"DY " << mCellSizeY << Qt::endl;
149 #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
150 outStream <<
"NODATA_VALUE -9999" << endl;
152 outStream <<
"NODATA_VALUE -9999" << Qt::endl;