Skip to content

Commit

Permalink
Modernize code
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 19, 2018
1 parent daa7391 commit 06766c4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
7 changes: 3 additions & 4 deletions src/core/raster/qgsrasterdataprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,13 @@ QgsRasterIdentifyResult QgsRasterDataProvider::identify( const QgsPointXY &point

for ( int i = 1; i <= bandCount(); i++ )
{
QgsRasterBlock *myBlock = block( i, pixelExtent, 1, 1 );
std::unique_ptr< QgsRasterBlock > bandBlock( block( i, pixelExtent, 1, 1 ) );

if ( myBlock )
if ( bandBlock )
{
double value = myBlock->value( 0 );
double value = bandBlock->value( 0 );

results.insert( i, value );
delete myBlock;
}
else
{
Expand Down
6 changes: 3 additions & 3 deletions src/providers/arcgisrest/qgsamsprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,13 +395,13 @@ QgsRasterIdentifyResult QgsAmsProvider::identify( const QgsPointXY &point, QgsRa
queryUrl.addQueryItem( QStringLiteral( "imageDisplay" ), QStringLiteral( "%1,%2,%3" ).arg( width ).arg( height ).arg( dpi ) );
queryUrl.addQueryItem( QStringLiteral( "mapExtent" ), QStringLiteral( "%1,%2,%3,%4" ).arg( extent.xMinimum(), 0, 'f' ).arg( extent.yMinimum(), 0, 'f' ).arg( extent.xMaximum(), 0, 'f' ).arg( extent.yMaximum(), 0, 'f' ) );
queryUrl.addQueryItem( QStringLiteral( "tolerance" ), QStringLiteral( "10" ) );
QVariantList queryResults = QgsArcGisRestUtils::queryServiceJSON( queryUrl, mErrorTitle, mError ).value( QStringLiteral( "results" ) ).toList();
const QVariantList queryResults = QgsArcGisRestUtils::queryServiceJSON( queryUrl, mErrorTitle, mError ).value( QStringLiteral( "results" ) ).toList();

QMap<int, QVariant> entries;

if ( format == QgsRaster::IdentifyFormatText )
{
foreach ( const QVariant &result, queryResults )
for ( const QVariant &result : queryResults )
{
const QVariantMap resultMap = result.toMap();
QVariantMap attributesMap = resultMap[QStringLiteral( "attributes" )].toMap();
Expand All @@ -415,7 +415,7 @@ QgsRasterIdentifyResult QgsAmsProvider::identify( const QgsPointXY &point, QgsRa
}
else if ( format == QgsRaster::IdentifyFormatFeature )
{
foreach ( const QVariant &result, queryResults )
for ( const QVariant &result : queryResults )
{
const QVariantMap resultMap = result.toMap();

Expand Down
20 changes: 11 additions & 9 deletions src/providers/gdal/qgsgdalprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1022,12 +1022,15 @@ QgsRasterIdentifyResult QgsGdalProvider::identify( const QgsPointXY &point, QgsR
}

QgsRectangle finalExtent = boundingBox;
if ( finalExtent.isEmpty() ) finalExtent = extent();
if ( finalExtent.isEmpty() )
finalExtent = extent();

QgsDebugMsgLevel( QStringLiteral( "myExtent = %1 " ).arg( finalExtent.toString() ), 3 );

if ( width == 0 ) width = xSize();
if ( height == 0 ) height = ySize();
if ( width == 0 )
width = xSize();
if ( height == 0 )
height = ySize();

QgsDebugMsgLevel( QStringLiteral( "theWidth = %1 height = %2" ).arg( width ).arg( height ), 3 );

Expand All @@ -1036,8 +1039,8 @@ QgsRasterIdentifyResult QgsGdalProvider::identify( const QgsPointXY &point, QgsR
double yres = ( finalExtent.height() ) / height;

// Offset, not the cell index -> std::floor
int col = ( int ) std::floor( ( point.x() - finalExtent.xMinimum() ) / xres );
int row = ( int ) std::floor( ( finalExtent.yMaximum() - point.y() ) / yres );
int col = static_cast< int >( std::floor( ( point.x() - finalExtent.xMinimum() ) / xres ) );
int row = static_cast< int >( std::floor( ( finalExtent.yMaximum() - point.y() ) / yres ) );

QgsDebugMsgLevel( QStringLiteral( "row = %1 col = %2" ).arg( row ).arg( col ), 3 );

Expand All @@ -1056,14 +1059,14 @@ QgsRasterIdentifyResult QgsGdalProvider::identify( const QgsPointXY &point, QgsR

for ( int i = 1; i <= bandCount(); i++ )
{
QgsRasterBlock *myBlock = block( i, pixelExtent, w, h );
std::unique_ptr< QgsRasterBlock > bandBlock( block( i, pixelExtent, w, h ) );

if ( !myBlock )
if ( !bandBlock )
{
return QgsRasterIdentifyResult( ERR( tr( "Cannot read data" ) ) );
}

double value = myBlock->value( r, c );
double value = bandBlock->value( r, c );

if ( ( sourceHasNoDataValue( i ) && useSourceNoDataValue( i ) &&
( std::isnan( value ) || qgsDoubleNear( value, sourceNoDataValue( i ) ) ) ) ||
Expand All @@ -1082,7 +1085,6 @@ QgsRasterIdentifyResult QgsGdalProvider::identify( const QgsPointXY &point, QgsR
else
results.insert( i, value );
}
delete myBlock;
}
return QgsRasterIdentifyResult( QgsRaster::IdentifyFormatValue, results );
}
Expand Down

0 comments on commit 06766c4

Please sign in to comment.