23 #include <QProgressDialog>
27 , mOutputFilePath( outputPath )
28 , mInterpolationExtent( extent )
29 , mNumColumns( nCols )
31 , mCellSizeX( cellSizeX )
32 , mCellSizeY( cellSizeY )
37 QgsGridFileWriter::QgsGridFileWriter()
54 QFile outputFile( mOutputFilePath );
56 if ( !outputFile.open( QFile::WriteOnly ) )
67 QTextStream outStream( &outputFile );
68 outStream.setRealNumberPrecision( 8 );
69 writeHeader( outStream );
71 double currentYValue = mInterpolationExtent.
yMaximum() - mCellSizeY / 2.0;
73 double interpolatedValue;
75 QProgressDialog* progressDialog = 0;
76 if ( showProgressDialog )
78 progressDialog =
new QProgressDialog(
QObject::tr(
"Interpolating..." ),
QObject::tr(
"Abort" ), 0, mNumRows, 0 );
79 progressDialog->setWindowModality( Qt::WindowModal );
82 for (
int i = 0; i < mNumRows; ++i )
84 currentXValue = mInterpolationExtent.
xMinimum() + mCellSizeX / 2.0;
85 for (
int j = 0; j < mNumColumns; ++j )
87 if ( mInterpolator->
interpolatePoint( currentXValue, currentYValue, interpolatedValue ) == 0 )
89 outStream << interpolatedValue <<
" ";
93 outStream <<
"-9999 ";
95 currentXValue += mCellSizeX;
98 currentYValue -= mCellSizeY;
100 if ( showProgressDialog )
102 if ( progressDialog->wasCanceled() )
107 progressDialog->setValue( i );
116 QFileInfo fi( mOutputFilePath );
117 QString fileName = fi.absolutePath() +
"/" + fi.completeBaseName() +
".prj";
118 QFile prjFile( fileName );
119 if ( !prjFile.open( QFile::WriteOnly ) )
123 QTextStream prjStream( &prjFile );
128 delete progressDialog;
132 int QgsGridFileWriter::writeHeader( QTextStream& outStream )
134 outStream <<
"NCOLS " << mNumColumns << endl;
135 outStream <<
"NROWS " << mNumRows << endl;
136 outStream <<
"XLLCORNER " << mInterpolationExtent.
xMinimum() << endl;
137 outStream <<
"YLLCORNER " << mInterpolationExtent.
yMinimum() << endl;
138 if ( mCellSizeX == mCellSizeY )
140 outStream <<
"CELLSIZE " << mCellSizeX << endl;
144 outStream <<
"DX " << mCellSizeX << endl;
145 outStream <<
"DY " << mCellSizeY << endl;
147 outStream <<
"NODATA_VALUE -9999" << endl;