Skip to content
Permalink
Browse files

Add some debug output when GDALRasterIO operations fail

Or the compiler will complain about unhandled returns
  • Loading branch information
m-kuhn committed Mar 10, 2016
1 parent 3dc40d7 commit 4cc5c2cb4c50c9d60927521fe23da1590b3311c5
@@ -16,6 +16,7 @@
***************************************************************************/

#include "qgsninecellfilter.h"
#include "qgslogger.h"
#include "cpl_string.h"
#include <QProgressDialog>
#include <QFile>
@@ -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
{
@@ -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 )
@@ -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 )
@@ -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;
@@ -15,6 +15,7 @@
* *
***************************************************************************/

#include "qgslogger.h"
#include "qgsrelief.h"
#include "qgsaspectfilter.h"
#include "qgshillshadefilter.h"
@@ -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
{
@@ -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 )
@@ -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 )
@@ -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 );
@@ -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 );
@@ -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;

@@ -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 );
@@ -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++ )
{
@@ -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 );
}
}
@@ -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++ )
@@ -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" ) );
}
}

0 comments on commit 4cc5c2c

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