Skip to content

Commit

Permalink
Throw exception when raster output could not be created
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 13, 2018
1 parent 85d895d commit b26957e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions python/plugins/processing/algs/qgis/CreateConstantRaster.py
Expand Up @@ -30,6 +30,8 @@
import struct

from qgis.core import (Qgis,
QgsErrorMessage,
QgsProcessingException,
QgsRasterBlock,
QgsRasterFileWriter,
QgsProcessingParameterExtent,
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/analysis/processing/qgsalgorithmreclassifybylayer.cpp
Expand Up @@ -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 );

Expand Down

0 comments on commit b26957e

Please sign in to comment.