mirror of
https://github.com/qgis/QGIS.git
synced 2025-06-20 00:03:07 -04:00
Throw exception when raster output could not be created
This commit is contained in:
parent
85d895d0e3
commit
b26957e41f
@ -30,6 +30,8 @@ import math
|
||||
import struct
|
||||
|
||||
from qgis.core import (Qgis,
|
||||
QgsErrorMessage,
|
||||
QgsProcessingException,
|
||||
QgsRasterBlock,
|
||||
QgsRasterFileWriter,
|
||||
QgsProcessingParameterExtent,
|
||||
@ -94,6 +96,12 @@ class CreateConstantRaster(QgisAlgorithm):
|
||||
writer.setOutputProviderKey('gdal')
|
||||
writer.setOutputFormat(outputFormat)
|
||||
provider = writer.createOneBandRaster(Qgis.Float32, cols, rows, extent, crs)
|
||||
if provider is None:
|
||||
raise QgsProcessingException(self.tr("Could not create raster output: {}").format(outputFile))
|
||||
if not provider.isValid():
|
||||
raise QgsProcessingException(self.tr("Could not create raster output {}: {}").arg(outputFile,
|
||||
provider.error().message(QgsErrorMessage.Text)))
|
||||
|
||||
provider.setNoDataValue(1, -9999)
|
||||
|
||||
data = [value] * cols
|
||||
|
@ -128,6 +128,8 @@ QVariantMap QgsReclassifyAlgorithmBase::processAlgorithm( const QVariantMap &par
|
||||
std::unique_ptr<QgsRasterDataProvider > provider( writer->createOneBandRaster( Qgis::Float32, mNbCellsXProvider, mNbCellsYProvider, mExtent, mCrs ) );
|
||||
if ( !provider )
|
||||
throw QgsProcessingException( QObject::tr( "Could not create raster output: %1" ).arg( outputFile ) );
|
||||
if ( !provider->isValid() )
|
||||
throw QgsProcessingException( QObject::tr( "Could not create raster output %1: %2" ).arg( outputFile, provider->error().message( QgsErrorMessage::Text ) ) );
|
||||
|
||||
provider->setNoDataValue( 1, mNoDataValue );
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user