Skip to content
Permalink
Browse files

Throw exception when raster output could not be created

  • Loading branch information
nyalldawson committed Jun 12, 2018
1 parent 85d895d commit b26957e41f2706b39803d9fabaf9d106a4afdd4b
@@ -30,6 +30,8 @@
import struct

from qgis.core import (Qgis,
QgsErrorMessage,
QgsProcessingException,
QgsRasterBlock,
QgsRasterFileWriter,
QgsProcessingParameterExtent,
@@ -94,6 +96,12 @@ def processAlgorithm(self, parameters, context, feedback):
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 );

0 comments on commit b26957e

Please sign in to comment.
You can’t perform that action at this time.