mirror of
https://github.com/qgis/QGIS.git
synced 2025-11-28 00:06:23 -05:00
add create options support to QgsGridFileWirter (follow-up 2aa6c5d)
This commit is contained in:
parent
33c34c581a
commit
a54654da92
@ -37,6 +37,24 @@ Writes the grid file.
|
|||||||
An optional ``feedback`` object can be set for progress reports and cancellation support
|
An optional ``feedback`` object can be set for progress reports and cancellation support
|
||||||
|
|
||||||
:return: 0 in case of success
|
:return: 0 in case of success
|
||||||
|
%End
|
||||||
|
|
||||||
|
void setCreateOptions( const QStringList &list );
|
||||||
|
%Docstring
|
||||||
|
Sets a list of data source creation options to use when creating the output raster file.
|
||||||
|
|
||||||
|
.. seealso:: :py:func:`createOptions`
|
||||||
|
|
||||||
|
.. versionadded:: 3.44
|
||||||
|
%End
|
||||||
|
|
||||||
|
QStringList createOptions() const;
|
||||||
|
%Docstring
|
||||||
|
Returns the list of data source creation options which will be used when creating the output raster file.
|
||||||
|
|
||||||
|
.. seealso:: :py:func:`setCreateOptions`
|
||||||
|
|
||||||
|
.. versionadded:: 3.44
|
||||||
%End
|
%End
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -37,6 +37,24 @@ Writes the grid file.
|
|||||||
An optional ``feedback`` object can be set for progress reports and cancellation support
|
An optional ``feedback`` object can be set for progress reports and cancellation support
|
||||||
|
|
||||||
:return: 0 in case of success
|
:return: 0 in case of success
|
||||||
|
%End
|
||||||
|
|
||||||
|
void setCreateOptions( const QStringList &list );
|
||||||
|
%Docstring
|
||||||
|
Sets a list of data source creation options to use when creating the output raster file.
|
||||||
|
|
||||||
|
.. seealso:: :py:func:`createOptions`
|
||||||
|
|
||||||
|
.. versionadded:: 3.44
|
||||||
|
%End
|
||||||
|
|
||||||
|
QStringList createOptions() const;
|
||||||
|
%Docstring
|
||||||
|
Returns the list of data source creation options which will be used when creating the output raster file.
|
||||||
|
|
||||||
|
.. seealso:: :py:func:`setCreateOptions`
|
||||||
|
|
||||||
|
.. versionadded:: 3.44
|
||||||
%End
|
%End
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -45,6 +45,7 @@ int QgsGridFileWriter::writeFile( QgsFeedback *feedback )
|
|||||||
auto writer = std::make_unique<QgsRasterFileWriter>( mOutputFilePath );
|
auto writer = std::make_unique<QgsRasterFileWriter>( mOutputFilePath );
|
||||||
writer->setOutputProviderKey( QStringLiteral( "gdal" ) );
|
writer->setOutputProviderKey( QStringLiteral( "gdal" ) );
|
||||||
writer->setOutputFormat( outputFormat );
|
writer->setOutputFormat( outputFormat );
|
||||||
|
writer->setCreateOptions( mCreateOptions );
|
||||||
|
|
||||||
std::unique_ptr<QgsRasterDataProvider> provider( writer->createOneBandRaster( Qgis::DataType::Float32, mNumColumns, mNumRows, mInterpolationExtent, crs ) );
|
std::unique_ptr<QgsRasterDataProvider> provider( writer->createOneBandRaster( Qgis::DataType::Float32, mNumColumns, mNumRows, mInterpolationExtent, crs ) );
|
||||||
if ( !provider )
|
if ( !provider )
|
||||||
|
|||||||
@ -53,6 +53,22 @@ class ANALYSIS_EXPORT QgsGridFileWriter
|
|||||||
*/
|
*/
|
||||||
int writeFile( QgsFeedback *feedback = nullptr );
|
int writeFile( QgsFeedback *feedback = nullptr );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a list of data source creation options to use when creating the output raster file.
|
||||||
|
*
|
||||||
|
* \see createOptions()
|
||||||
|
* \since QGIS 3.44t
|
||||||
|
*/
|
||||||
|
void setCreateOptions( const QStringList &list ) { mCreateOptions = list; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the list of data source creation options which will be used when creating the output raster file.
|
||||||
|
*
|
||||||
|
* \see setCreateOptions()
|
||||||
|
* \since QGIS 3.44
|
||||||
|
*/
|
||||||
|
QStringList createOptions() const { return mCreateOptions; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QgsGridFileWriter() = delete;
|
QgsGridFileWriter() = delete;
|
||||||
|
|
||||||
@ -64,6 +80,8 @@ class ANALYSIS_EXPORT QgsGridFileWriter
|
|||||||
|
|
||||||
double mCellSizeX = 0;
|
double mCellSizeX = 0;
|
||||||
double mCellSizeY = 0;
|
double mCellSizeY = 0;
|
||||||
|
|
||||||
|
QStringList mCreateOptions;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -79,6 +79,23 @@ class TestInterpolation(QgisTestCase):
|
|||||||
writer = QgsGridFileWriter(interpolator, output_file, extent, cols, rows)
|
writer = QgsGridFileWriter(interpolator, output_file, extent, cols, rows)
|
||||||
writer.writeFile()
|
writer.writeFile()
|
||||||
|
|
||||||
|
checker = QgsRasterChecker()
|
||||||
|
ok = checker.runTest(
|
||||||
|
"gdal",
|
||||||
|
output_file,
|
||||||
|
"gdal",
|
||||||
|
os.path.join(TEST_DATA_DIR, "analysis", "idw_interpolation.tif"),
|
||||||
|
)
|
||||||
|
self.report += checker.report()
|
||||||
|
self.assertTrue(ok)
|
||||||
|
|
||||||
|
tfw_file = os.path.join(tempfile.gettempdir(), "idw_interpolation.tfw")
|
||||||
|
self.assertFalse(os.path.exists(tfw_file))
|
||||||
|
|
||||||
|
# with raster creation options
|
||||||
|
writer.setCreateOptions(["TFW=yes"])
|
||||||
|
writer.writeFile()
|
||||||
|
|
||||||
checker = QgsRasterChecker()
|
checker = QgsRasterChecker()
|
||||||
ok = checker.runTest(
|
ok = checker.runTest(
|
||||||
"gdal",
|
"gdal",
|
||||||
@ -93,6 +110,7 @@ class TestInterpolation(QgisTestCase):
|
|||||||
f.write(self.report)
|
f.write(self.report)
|
||||||
|
|
||||||
self.assertTrue(ok)
|
self.assertTrue(ok)
|
||||||
|
self.assertTrue(os.path.exists(tfw_file))
|
||||||
|
|
||||||
def test_tin_interpolator(self):
|
def test_tin_interpolator(self):
|
||||||
layer = QgsVectorLayer(
|
layer = QgsVectorLayer(
|
||||||
@ -124,6 +142,22 @@ class TestInterpolation(QgisTestCase):
|
|||||||
writer.writeFile()
|
writer.writeFile()
|
||||||
|
|
||||||
checker = QgsRasterChecker()
|
checker = QgsRasterChecker()
|
||||||
|
ok = checker.runTest(
|
||||||
|
"gdal",
|
||||||
|
output_file,
|
||||||
|
"gdal",
|
||||||
|
os.path.join(TEST_DATA_DIR, "analysis", "tin_interpolation.tif"),
|
||||||
|
)
|
||||||
|
self.report += checker.report()
|
||||||
|
self.assertTrue(ok)
|
||||||
|
|
||||||
|
tfw_file = os.path.join(tempfile.gettempdir(), "tin_interpolation.tfw")
|
||||||
|
self.assertFalse(os.path.exists(tfw_file))
|
||||||
|
|
||||||
|
# with raster creation options
|
||||||
|
writer.setCreateOptions(["TFW=yes"])
|
||||||
|
writer.writeFile()
|
||||||
|
|
||||||
ok = checker.runTest(
|
ok = checker.runTest(
|
||||||
"gdal",
|
"gdal",
|
||||||
output_file,
|
output_file,
|
||||||
@ -137,6 +171,7 @@ class TestInterpolation(QgisTestCase):
|
|||||||
f.write(self.report)
|
f.write(self.report)
|
||||||
|
|
||||||
self.assertTrue(ok)
|
self.assertTrue(ok)
|
||||||
|
self.assertTrue(os.path.exists(tfw_file))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user