Skip to content

Commit 4cc5c2c

Browse files
committed
Add some debug output when GDALRasterIO operations fail
Or the compiler will complain about unhandled returns
1 parent 3dc40d7 commit 4cc5c2c

File tree

6 files changed

+51
-25
lines changed

6 files changed

+51
-25
lines changed

src/analysis/raster/qgsninecellfilter.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
***************************************************************************/
1717

1818
#include "qgsninecellfilter.h"
19+
#include "qgslogger.h"
1920
#include "cpl_string.h"
2021
#include <QProgressDialog>
2122
#include <QFile>
@@ -138,7 +139,8 @@ int QgsNineCellFilter::processRaster( QProgressDialog* p )
138139
{
139140
scanLine1[a] = mInputNodataValue;
140141
}
141-
GDALRasterIO( rasterBand, GF_Read, 0, 0, xSize, 1, scanLine2, xSize, 1, GDT_Float32, 0, 0 );
142+
if ( GDALRasterIO( rasterBand, GF_Read, 0, 0, xSize, 1, scanLine2, xSize, 1, GDT_Float32, 0, 0 ) != CE_None )
143+
QgsDebugMsg( "Raster IO Error" );
142144
}
143145
else
144146
{
@@ -158,7 +160,8 @@ int QgsNineCellFilter::processRaster( QProgressDialog* p )
158160
}
159161
else
160162
{
161-
GDALRasterIO( rasterBand, GF_Read, 0, i + 1, xSize, 1, scanLine3, xSize, 1, GDT_Float32, 0, 0 );
163+
if ( GDALRasterIO( rasterBand, GF_Read, 0, i + 1, xSize, 1, scanLine3, xSize, 1, GDT_Float32, 0, 0 ) != CE_None )
164+
QgsDebugMsg( "Raster IO Error" );
162165
}
163166

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

183-
GDALRasterIO( outputRasterBand, GF_Write, 0, i, xSize, 1, resultLine, xSize, 1, GDT_Float32, 0, 0 );
186+
if ( GDALRasterIO( outputRasterBand, GF_Write, 0, i, xSize, 1, resultLine, xSize, 1, GDT_Float32, 0, 0 ) != CE_None )
187+
QgsDebugMsg( "Raster IO Error" );
184188
}
185189

186190
if ( p )

src/analysis/raster/qgsrastercalculator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ int QgsRasterCalculator::processCalculation( QProgressDialog* p )
156156
//write scanline to the dataset
157157
if ( GDALRasterIO( outputRasterBand, GF_Write, 0, i, mNumOutputColumns, 1, calcData, mNumOutputColumns, 1, GDT_Float32, 0, 0 ) != CE_None )
158158
{
159-
qWarning( "RasterIO error!" );
159+
QgsDebugMsg( "RasterIO error!" );
160160
}
161161

162162
delete[] calcData;

src/analysis/raster/qgsrelief.cpp

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* *
1616
***************************************************************************/
1717

18+
#include "qgslogger.h"
1819
#include "qgsrelief.h"
1920
#include "qgsaspectfilter.h"
2021
#include "qgshillshadefilter.h"
@@ -202,7 +203,8 @@ int QgsRelief::processRaster( QProgressDialog* p )
202203
{
203204
scanLine1[a] = mInputNodataValue;
204205
}
205-
GDALRasterIO( rasterBand, GF_Read, 0, 0, xSize, 1, scanLine2, xSize, 1, GDT_Float32, 0, 0 );
206+
if ( GDALRasterIO( rasterBand, GF_Read, 0, 0, xSize, 1, scanLine2, xSize, 1, GDT_Float32, 0, 0 ) != CE_None )
207+
QgsDebugMsg( "Raster IO Error" );
206208
}
207209
else
208210
{
@@ -222,7 +224,8 @@ int QgsRelief::processRaster( QProgressDialog* p )
222224
}
223225
else
224226
{
225-
GDALRasterIO( rasterBand, GF_Read, 0, i + 1, xSize, 1, scanLine3, xSize, 1, GDT_Float32, 0, 0 );
227+
if ( GDALRasterIO( rasterBand, GF_Read, 0, i + 1, xSize, 1, scanLine3, xSize, 1, GDT_Float32, 0, 0 ) != CE_None )
228+
QgsDebugMsg( "Raster IO Error" );
226229
}
227230

228231
for ( int j = 0; j < xSize; ++j )
@@ -254,9 +257,12 @@ int QgsRelief::processRaster( QProgressDialog* p )
254257
}
255258
}
256259

257-
GDALRasterIO( outputRedBand, GF_Write, 0, i, xSize, 1, resultRedLine, xSize, 1, GDT_Byte, 0, 0 );
258-
GDALRasterIO( outputGreenBand, GF_Write, 0, i, xSize, 1, resultGreenLine, xSize, 1, GDT_Byte, 0, 0 );
259-
GDALRasterIO( outputBlueBand, GF_Write, 0, i, xSize, 1, resultBlueLine, xSize, 1, GDT_Byte, 0, 0 );
260+
if ( GDALRasterIO( outputRedBand, GF_Write, 0, i, xSize, 1, resultRedLine, xSize, 1, GDT_Byte, 0, 0 ) != CE_None )
261+
QgsDebugMsg( "Raster IO Error" );
262+
if ( GDALRasterIO( outputGreenBand, GF_Write, 0, i, xSize, 1, resultGreenLine, xSize, 1, GDT_Byte, 0, 0 ) != CE_None )
263+
QgsDebugMsg( "Raster IO Error" );
264+
if ( GDALRasterIO( outputBlueBand, GF_Write, 0, i, xSize, 1, resultBlueLine, xSize, 1, GDT_Byte, 0, 0 ) != CE_None )
265+
QgsDebugMsg( "Raster IO Error" );
260266
}
261267

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

532538
for ( int i = 0; i < nCellsY; ++i )
533539
{
534-
GDALRasterIO( elevationBand, GF_Read, 0, i, nCellsX, 1,
535-
scanLine, nCellsX, 1, GDT_Float32,
536-
0, 0 );
540+
if ( GDALRasterIO( elevationBand, GF_Read, 0, i, nCellsX, 1,
541+
scanLine, nCellsX, 1, GDT_Float32,
542+
0, 0 ) != CE_None )
543+
{
544+
QgsDebugMsg( "Raster IO Error" );
545+
}
546+
537547
for ( int j = 0; j < nCellsX; ++j )
538548
{
539549
elevationClass = frequencyClassForElevation( scanLine[j], minMax[0], frequencyClassRange );
@@ -614,9 +624,12 @@ QList< QgsRelief::ReliefColor > QgsRelief::calculateOptimizedReliefClasses()
614624

615625
for ( int i = 0; i < nCellsY; ++i )
616626
{
617-
GDALRasterIO( elevationBand, GF_Read, 0, i, nCellsX, 1,
618-
scanLine, nCellsX, 1, GDT_Float32,
619-
0, 0 );
627+
if ( GDALRasterIO( elevationBand, GF_Read, 0, i, nCellsX, 1,
628+
scanLine, nCellsX, 1, GDT_Float32,
629+
0, 0 ) != CE_None )
630+
{
631+
QgsDebugMsg( "Raster IO Error" );
632+
}
620633
for ( int j = 0; j < nCellsX; ++j )
621634
{
622635
elevationClass = frequencyClassForElevation( scanLine[j], minMax[0], frequencyClassRange );

src/analysis/vector/qgszonalstatistics.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,9 @@ void QgsZonalStatistics::statisticsFromPreciseIntersection( void* band, const Qg
482482
double currentX = rasterBBox.xMinimum() + cellSizeX / 2.0 + pixelOffsetX * cellSizeX;
483483
for ( int col = 0; col < nCellsX; ++col )
484484
{
485-
GDALRasterIO( band, GF_Read, pixelOffsetX + col, pixelOffsetY + row, nCellsX, 1, pixelData, 1, 1, GDT_Float32, 0, 0 );
485+
if ( GDALRasterIO( band, GF_Read, pixelOffsetX + col, pixelOffsetY + row, nCellsX, 1, pixelData, 1, 1, GDT_Float32, 0, 0 ) != CE_None )
486+
QgsDebugMsg( "Raster IO Error" );
487+
486488
if ( !validPixel( *pixelData ) )
487489
continue;
488490

src/plugins/heatmap/heatmap.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ void Heatmap::run()
170170
// Write the empty raster
171171
for ( int i = 0; i < rows ; i++ )
172172
{
173-
poBand->RasterIO( GF_Write, 0, i, columns, 1, line, columns, 1, GDT_Float32, 0, 0 );
173+
if ( poBand->RasterIO( GF_Write, 0, i, columns, 1, line, columns, 1, GDT_Float32, 0, 0 ) != CE_None )
174+
QgsDebugMsg( "Raster IO Error" );
174175
}
175176

176177
CPLFree( line );
@@ -299,8 +300,9 @@ void Heatmap::run()
299300

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

305307
for ( int xp = 0; xp <= myBuffer; xp++ )
306308
{
@@ -341,8 +343,9 @@ void Heatmap::run()
341343
}
342344
}
343345
}
344-
poBand->RasterIO( GF_Write, xPosition, yPosition, blockSize, blockSize,
345-
dataBuffer, blockSize, blockSize, GDT_Float32, 0, 0 );
346+
if ( poBand->RasterIO( GF_Write, xPosition, yPosition, blockSize, blockSize,
347+
dataBuffer, blockSize, blockSize, GDT_Float32, 0, 0 ) != CE_None )
348+
QgsDebugMsg( "Raster IO Error" );
346349
CPLFree( dataBuffer );
347350
}
348351
}

src/providers/wcs/qgswcsprovider.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,8 @@ void QgsWcsProvider::readBlock( int bandNo, QgsRectangle const & viewExtent, in
587587
QgsDebugMsg( QString( "Couldn't allocate memory of %1 bytes" ).arg( size ) );
588588
return;
589589
}
590-
GDALRasterIO( gdalBand, GF_Read, 0, 0, width, height, tmpData, width, height, ( GDALDataType ) mGdalDataType.at( bandNo - 1 ), 0, 0 );
590+
if ( GDALRasterIO( gdalBand, GF_Read, 0, 0, width, height, tmpData, width, height, ( GDALDataType ) mGdalDataType.at( bandNo - 1 ), 0, 0 ) != CE_None )
591+
QgsDebugMsg( "Raster IO Error" );
591592
for ( int i = 0; i < pixelHeight; i++ )
592593
{
593594
for ( int j = 0; j < pixelWidth; j++ )
@@ -601,13 +602,16 @@ void QgsWcsProvider::readBlock( int bandNo, QgsRectangle const & viewExtent, in
601602
}
602603
else if ( width == pixelWidth && height == pixelHeight )
603604
{
604-
GDALRasterIO( gdalBand, GF_Read, 0, 0, pixelWidth, pixelHeight, block, pixelWidth, pixelHeight, ( GDALDataType ) mGdalDataType.at( bandNo - 1 ), 0, 0 );
605-
QgsDebugMsg( tr( "Block read OK" ) );
605+
if ( GDALRasterIO( gdalBand, GF_Read, 0, 0, pixelWidth, pixelHeight, block, pixelWidth, pixelHeight, ( GDALDataType ) mGdalDataType.at( bandNo - 1 ), 0, 0 ) != CE_None )
606+
QgsDebugMsg( "Raster IO Error" );
607+
else
608+
QgsDebugMsg( "Block read OK" );
606609
}
607610
else
608611
{
609612
// This should not happen, but it is better to give distorted result + warning
610-
GDALRasterIO( gdalBand, GF_Read, 0, 0, width, height, block, pixelWidth, pixelHeight, ( GDALDataType ) mGdalDataType.at( bandNo - 1 ), 0, 0 );
613+
if ( GDALRasterIO( gdalBand, GF_Read, 0, 0, width, height, block, pixelWidth, pixelHeight, ( GDALDataType ) mGdalDataType.at( bandNo - 1 ), 0, 0 ) != CE_None )
614+
QgsDebugMsg( "Raster IO Error" );
611615
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" ) );
612616
}
613617
}

0 commit comments

Comments
 (0)