Throw exception when raster output could not be created

This commit is contained in:
Nyall Dawson 2018-06-12 10:46:53 +10:00
parent 85d895d0e3
commit b26957e41f
2 changed files with 10 additions and 0 deletions

View File

@ -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

View File

@ -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 );