23 #include <QProgressDialog> 27 , mOutputFilePath( outputPath )
28 , mInterpolationExtent( extent )
29 , mNumColumns( nCols )
31 , mCellSizeX( cellSizeX )
32 , mCellSizeY( cellSizeY )
38 : mInterpolator(
nullptr )
49 QFile outputFile( mOutputFilePath );
51 if ( !outputFile.
open( QFile::WriteOnly ) )
64 writeHeader( outStream );
66 double currentYValue = mInterpolationExtent.
yMaximum() - mCellSizeY / 2.0;
68 double interpolatedValue;
71 if ( showProgressDialog )
77 for (
int i = 0; i < mNumRows; ++i )
79 currentXValue = mInterpolationExtent.
xMinimum() + mCellSizeX / 2.0;
80 for (
int j = 0; j < mNumColumns; ++j )
82 if ( mInterpolator->
interpolatePoint( currentXValue, currentYValue, interpolatedValue ) == 0 )
84 outStream << interpolatedValue <<
' ';
88 outStream <<
"-9999 ";
90 currentXValue += mCellSizeX;
93 currentYValue -= mCellSizeY;
95 if ( showProgressDialog )
113 QFile prjFile( fileName );
114 if ( !prjFile.
open( QFile::WriteOnly ) )
123 delete progressDialog;
127 int QgsGridFileWriter::writeHeader(
QTextStream& outStream )
129 outStream <<
"NCOLS " << mNumColumns << endl;
130 outStream <<
"NROWS " << mNumRows << endl;
131 outStream <<
"XLLCORNER " << mInterpolationExtent.
xMinimum() << endl;
132 outStream <<
"YLLCORNER " << mInterpolationExtent.
yMinimum() << endl;
133 if ( mCellSizeX == mCellSizeY )
135 outStream <<
"CELLSIZE " << mCellSizeX << endl;
139 outStream <<
"DX " << mCellSizeX << endl;
140 outStream <<
"DY " << mCellSizeY << endl;
142 outStream <<
"NODATA_VALUE -9999" << endl;
A rectangle specified with double values.
Interface class for interpolations.
QgsVectorLayer * vectorLayer
void setRealNumberPrecision(int precision)
const QgsCoordinateReferenceSystem & crs() const
Returns layer's spatial reference system.
QString tr(const char *sourceText, const char *disambiguation, int n)
int writeFile(bool showProgressDialog=false)
Writes the grid file.
void setValue(int progress)
const QList< LayerData > & layerData() const
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
A layer together with the information about interpolation attribute / z-coordinate interpolation and ...
QgsGridFileWriter(QgsInterpolator *i, const QString &outputPath, const QgsRectangle &extent, int nCols, int nRows, double cellSizeX, double cellSizeY)
QString toWkt() const
Returns a WKT representation of this CRS.
virtual int interpolatePoint(double x, double y, double &result)=0
Calculates interpolation value for map coordinates x, y.
double xMinimum() const
Get the x minimum value (left side of rectangle)
QString completeBaseName() const
double yMaximum() const
Get the y maximum value (top side of rectangle)
QString absolutePath() const
Represents a vector layer which manages a vector based data sets.