Skip to content
Permalink
Browse files

Modernize code

  • Loading branch information
nyalldawson committed Jul 12, 2018
1 parent daa7391 commit 06766c4cd2ce1824748401f0437c6f2c16e15ed5
@@ -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
{
@@ -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();
@@ -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();

@@ -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 );

@@ -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 );

@@ -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 ) ) ) ) ||
@@ -1082,7 +1085,6 @@ QgsRasterIdentifyResult QgsGdalProvider::identify( const QgsPointXY &point, QgsR
else
results.insert( i, value );
}
delete myBlock;
}
return QgsRasterIdentifyResult( QgsRaster::IdentifyFormatValue, results );
}

0 comments on commit 06766c4

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