Skip to content

Commit

Permalink
Add some debug output when GDALRasterIO operations fail
Browse files Browse the repository at this point in the history
Or the compiler will complain about unhandled returns
  • Loading branch information
m-kuhn committed Mar 10, 2016
1 parent 3dc40d7 commit 4cc5c2c
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 25 deletions.
10 changes: 7 additions & 3 deletions src/analysis/raster/qgsninecellfilter.cpp
Expand Up @@ -16,6 +16,7 @@
***************************************************************************/

#include "qgsninecellfilter.h"
#include "qgslogger.h"
#include "cpl_string.h"
#include <QProgressDialog>
#include <QFile>
Expand Down Expand Up @@ -138,7 +139,8 @@ int QgsNineCellFilter::processRaster( QProgressDialog* p )
{
scanLine1[a] = mInputNodataValue;
}
GDALRasterIO( rasterBand, GF_Read, 0, 0, xSize, 1, scanLine2, xSize, 1, GDT_Float32, 0, 0 );
if ( GDALRasterIO( rasterBand, GF_Read, 0, 0, xSize, 1, scanLine2, xSize, 1, GDT_Float32, 0, 0 ) != CE_None )
QgsDebugMsg( "Raster IO Error" );
}
else
{
Expand All @@ -158,7 +160,8 @@ int QgsNineCellFilter::processRaster( QProgressDialog* p )
}
else
{
GDALRasterIO( rasterBand, GF_Read, 0, i + 1, xSize, 1, scanLine3, xSize, 1, GDT_Float32, 0, 0 );
if ( GDALRasterIO( rasterBand, GF_Read, 0, i + 1, xSize, 1, scanLine3, xSize, 1, GDT_Float32, 0, 0 ) != CE_None )
QgsDebugMsg( "Raster IO Error" );
}

for ( int j = 0; j < xSize; ++j )
Expand All @@ -180,7 +183,8 @@ int QgsNineCellFilter::processRaster( QProgressDialog* p )
}
}

GDALRasterIO( outputRasterBand, GF_Write, 0, i, xSize, 1, resultLine, xSize, 1, GDT_Float32, 0, 0 );
if ( GDALRasterIO( outputRasterBand, GF_Write, 0, i, xSize, 1, resultLine, xSize, 1, GDT_Float32, 0, 0 ) != CE_None )
QgsDebugMsg( "Raster IO Error" );
}

if ( p )
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/raster/qgsrastercalculator.cpp
Expand Up @@ -156,7 +156,7 @@ int QgsRasterCalculator::processCalculation( QProgressDialog* p )
//write scanline to the dataset
if ( GDALRasterIO( outputRasterBand, GF_Write, 0, i, mNumOutputColumns, 1, calcData, mNumOutputColumns, 1, GDT_Float32, 0, 0 ) != CE_None )
{
qWarning( "RasterIO error!" );
QgsDebugMsg( "RasterIO error!" );
}

delete[] calcData;
Expand Down
35 changes: 24 additions & 11 deletions src/analysis/raster/qgsrelief.cpp
Expand Up @@ -15,6 +15,7 @@
* *
***************************************************************************/

#include "qgslogger.h"
#include "qgsrelief.h"
#include "qgsaspectfilter.h"
#include "qgshillshadefilter.h"
Expand Down Expand Up @@ -202,7 +203,8 @@ int QgsRelief::processRaster( QProgressDialog* p )
{
scanLine1[a] = mInputNodataValue;
}
GDALRasterIO( rasterBand, GF_Read, 0, 0, xSize, 1, scanLine2, xSize, 1, GDT_Float32, 0, 0 );
if ( GDALRasterIO( rasterBand, GF_Read, 0, 0, xSize, 1, scanLine2, xSize, 1, GDT_Float32, 0, 0 ) != CE_None )
QgsDebugMsg( "Raster IO Error" );
}
else
{
Expand All @@ -222,7 +224,8 @@ int QgsRelief::processRaster( QProgressDialog* p )
}
else
{
GDALRasterIO( rasterBand, GF_Read, 0, i + 1, xSize, 1, scanLine3, xSize, 1, GDT_Float32, 0, 0 );
if ( GDALRasterIO( rasterBand, GF_Read, 0, i + 1, xSize, 1, scanLine3, xSize, 1, GDT_Float32, 0, 0 ) != CE_None )
QgsDebugMsg( "Raster IO Error" );
}

for ( int j = 0; j < xSize; ++j )
Expand Down Expand Up @@ -254,9 +257,12 @@ int QgsRelief::processRaster( QProgressDialog* p )
}
}

GDALRasterIO( outputRedBand, GF_Write, 0, i, xSize, 1, resultRedLine, xSize, 1, GDT_Byte, 0, 0 );
GDALRasterIO( outputGreenBand, GF_Write, 0, i, xSize, 1, resultGreenLine, xSize, 1, GDT_Byte, 0, 0 );
GDALRasterIO( outputBlueBand, GF_Write, 0, i, xSize, 1, resultBlueLine, xSize, 1, GDT_Byte, 0, 0 );
if ( GDALRasterIO( outputRedBand, GF_Write, 0, i, xSize, 1, resultRedLine, xSize, 1, GDT_Byte, 0, 0 ) != CE_None )
QgsDebugMsg( "Raster IO Error" );
if ( GDALRasterIO( outputGreenBand, GF_Write, 0, i, xSize, 1, resultGreenLine, xSize, 1, GDT_Byte, 0, 0 ) != CE_None )
QgsDebugMsg( "Raster IO Error" );
if ( GDALRasterIO( outputBlueBand, GF_Write, 0, i, xSize, 1, resultBlueLine, xSize, 1, GDT_Byte, 0, 0 ) != CE_None )
QgsDebugMsg( "Raster IO Error" );
}

if ( p )
Expand Down Expand Up @@ -531,9 +537,13 @@ bool QgsRelief::exportFrequencyDistributionToCsv( const QString& file )

for ( int i = 0; i < nCellsY; ++i )
{
GDALRasterIO( elevationBand, GF_Read, 0, i, nCellsX, 1,
scanLine, nCellsX, 1, GDT_Float32,
0, 0 );
if ( GDALRasterIO( elevationBand, GF_Read, 0, i, nCellsX, 1,
scanLine, nCellsX, 1, GDT_Float32,
0, 0 ) != CE_None )
{
QgsDebugMsg( "Raster IO Error" );
}

for ( int j = 0; j < nCellsX; ++j )
{
elevationClass = frequencyClassForElevation( scanLine[j], minMax[0], frequencyClassRange );
Expand Down Expand Up @@ -614,9 +624,12 @@ QList< QgsRelief::ReliefColor > QgsRelief::calculateOptimizedReliefClasses()

for ( int i = 0; i < nCellsY; ++i )
{
GDALRasterIO( elevationBand, GF_Read, 0, i, nCellsX, 1,
scanLine, nCellsX, 1, GDT_Float32,
0, 0 );
if ( GDALRasterIO( elevationBand, GF_Read, 0, i, nCellsX, 1,
scanLine, nCellsX, 1, GDT_Float32,
0, 0 ) != CE_None )
{
QgsDebugMsg( "Raster IO Error" );
}
for ( int j = 0; j < nCellsX; ++j )
{
elevationClass = frequencyClassForElevation( scanLine[j], minMax[0], frequencyClassRange );
Expand Down
4 changes: 3 additions & 1 deletion src/analysis/vector/qgszonalstatistics.cpp
Expand Up @@ -482,7 +482,9 @@ void QgsZonalStatistics::statisticsFromPreciseIntersection( void* band, const Qg
double currentX = rasterBBox.xMinimum() + cellSizeX / 2.0 + pixelOffsetX * cellSizeX;
for ( int col = 0; col < nCellsX; ++col )
{
GDALRasterIO( band, GF_Read, pixelOffsetX + col, pixelOffsetY + row, nCellsX, 1, pixelData, 1, 1, GDT_Float32, 0, 0 );
if ( GDALRasterIO( band, GF_Read, pixelOffsetX + col, pixelOffsetY + row, nCellsX, 1, pixelData, 1, 1, GDT_Float32, 0, 0 ) != CE_None )
QgsDebugMsg( "Raster IO Error" );

if ( !validPixel( *pixelData ) )
continue;

Expand Down
13 changes: 8 additions & 5 deletions src/plugins/heatmap/heatmap.cpp
Expand Up @@ -170,7 +170,8 @@ void Heatmap::run()
// Write the empty raster
for ( int i = 0; i < rows ; i++ )
{
poBand->RasterIO( GF_Write, 0, i, columns, 1, line, columns, 1, GDT_Float32, 0, 0 );
if ( poBand->RasterIO( GF_Write, 0, i, columns, 1, line, columns, 1, GDT_Float32, 0, 0 ) != CE_None )
QgsDebugMsg( "Raster IO Error" );
}

CPLFree( line );
Expand Down Expand Up @@ -299,8 +300,9 @@ void Heatmap::run()

// get the data
float *dataBuffer = ( float * ) CPLMalloc( sizeof( float ) * blockSize * blockSize );
poBand->RasterIO( GF_Read, xPosition, yPosition, blockSize, blockSize,
dataBuffer, blockSize, blockSize, GDT_Float32, 0, 0 );
if ( poBand->RasterIO( GF_Read, xPosition, yPosition, blockSize, blockSize,
dataBuffer, blockSize, blockSize, GDT_Float32, 0, 0 ) != CE_None )
QgsDebugMsg( "Raster IO Error" );

for ( int xp = 0; xp <= myBuffer; xp++ )
{
Expand Down Expand Up @@ -341,8 +343,9 @@ void Heatmap::run()
}
}
}
poBand->RasterIO( GF_Write, xPosition, yPosition, blockSize, blockSize,
dataBuffer, blockSize, blockSize, GDT_Float32, 0, 0 );
if ( poBand->RasterIO( GF_Write, xPosition, yPosition, blockSize, blockSize,
dataBuffer, blockSize, blockSize, GDT_Float32, 0, 0 ) != CE_None )
QgsDebugMsg( "Raster IO Error" );
CPLFree( dataBuffer );
}
}
Expand Down
12 changes: 8 additions & 4 deletions src/providers/wcs/qgswcsprovider.cpp
Expand Up @@ -587,7 +587,8 @@ void QgsWcsProvider::readBlock( int bandNo, QgsRectangle const & viewExtent, in
QgsDebugMsg( QString( "Couldn't allocate memory of %1 bytes" ).arg( size ) );
return;
}
GDALRasterIO( gdalBand, GF_Read, 0, 0, width, height, tmpData, width, height, ( GDALDataType ) mGdalDataType.at( bandNo - 1 ), 0, 0 );
if ( GDALRasterIO( gdalBand, GF_Read, 0, 0, width, height, tmpData, width, height, ( GDALDataType ) mGdalDataType.at( bandNo - 1 ), 0, 0 ) != CE_None )
QgsDebugMsg( "Raster IO Error" );
for ( int i = 0; i < pixelHeight; i++ )
{
for ( int j = 0; j < pixelWidth; j++ )
Expand All @@ -601,13 +602,16 @@ void QgsWcsProvider::readBlock( int bandNo, QgsRectangle const & viewExtent, in
}
else if ( width == pixelWidth && height == pixelHeight )
{
GDALRasterIO( gdalBand, GF_Read, 0, 0, pixelWidth, pixelHeight, block, pixelWidth, pixelHeight, ( GDALDataType ) mGdalDataType.at( bandNo - 1 ), 0, 0 );
QgsDebugMsg( tr( "Block read OK" ) );
if ( GDALRasterIO( gdalBand, GF_Read, 0, 0, pixelWidth, pixelHeight, block, pixelWidth, pixelHeight, ( GDALDataType ) mGdalDataType.at( bandNo - 1 ), 0, 0 ) != CE_None )
QgsDebugMsg( "Raster IO Error" );
else
QgsDebugMsg( "Block read OK" );
}
else
{
// This should not happen, but it is better to give distorted result + warning
GDALRasterIO( gdalBand, GF_Read, 0, 0, width, height, block, pixelWidth, pixelHeight, ( GDALDataType ) mGdalDataType.at( bandNo - 1 ), 0, 0 );
if ( GDALRasterIO( gdalBand, GF_Read, 0, 0, width, height, block, pixelWidth, pixelHeight, ( GDALDataType ) mGdalDataType.at( bandNo - 1 ), 0, 0 ) != CE_None )
QgsDebugMsg( "Raster IO Error" );
QgsMessageLog::logMessage( tr( "Received coverage has wrong size %1 x %2 (expected %3 x %4)" ).arg( width ).arg( height ).arg( pixelWidth ).arg( pixelHeight ), tr( "WCS" ) );
}
}
Expand Down

0 comments on commit 4cc5c2c

Please sign in to comment.