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 outStream.setRealNumberPrecision( 8 );
52 writeHeader( outStream );
54 double currentYValue = mInterpolationExtent.
yMaximum() - mCellSizeY / 2.0;
56 double interpolatedValue;
58 for (
int i = 0; i < mNumRows; ++i )
60 currentXValue = mInterpolationExtent.
xMinimum() + mCellSizeX / 2.0;
61 for (
int j = 0; j < mNumColumns; ++j )
63 if ( mInterpolator->
interpolatePoint( currentXValue, currentYValue, interpolatedValue, feedback ) == 0 )
65 outStream << interpolatedValue <<
' ';
69 outStream <<
"-9999 ";
71 currentXValue += mCellSizeX;
74 currentYValue -= mCellSizeY;
83 feedback->
setProgress( 100.0 * i /
static_cast< double >( mNumRows ) );
92 QFileInfo fi( mOutputFilePath );
93 QString fileName = fi.absolutePath() +
'/' + fi.completeBaseName() +
".prj";
94 QFile prjFile( fileName );
95 if ( !prjFile.open( QFile::WriteOnly | QIODevice::Truncate ) )
99 QTextStream prjStream( &prjFile );
107 int QgsGridFileWriter::writeHeader( QTextStream &outStream )
109 outStream <<
"NCOLS " << mNumColumns << endl;
110 outStream <<
"NROWS " << mNumRows << endl;
111 outStream <<
"XLLCORNER " << mInterpolationExtent.
xMinimum() << endl;
112 outStream <<
"YLLCORNER " << mInterpolationExtent.
yMinimum() << endl;
113 if ( mCellSizeX == mCellSizeY )
115 outStream <<
"CELLSIZE " << mCellSizeX << endl;
119 outStream <<
"DX " << mCellSizeX << endl;
120 outStream <<
"DY " << mCellSizeY << endl;
122 outStream <<
"NODATA_VALUE -9999" << endl;