@@ -376,8 +376,6 @@ bool QgsMapToolIdentify::identifyRasterLayer( QList<IdentifyResult> *results, Qg
376
376
377
377
QMap< QString, QString > attributes, derivedAttributes;
378
378
379
- QMap<int , QVariant> values;
380
-
381
379
QgsRaster::IdentifyFormat format = QgsRasterDataProvider::identifyFormatFromName ( layer->customProperty ( " identify/format" ).toString () );
382
380
383
381
// check if the format is really supported otherwise use first supported format
@@ -390,12 +388,13 @@ bool QgsMapToolIdentify::identifyRasterLayer( QList<IdentifyResult> *results, Qg
390
388
else return false ;
391
389
}
392
390
391
+ QgsRasterIdentifyResult identifyResult;
393
392
// We can only use context (extent, width, height) if layer is not reprojected,
394
393
// otherwise we don't know source resolution (size).
395
394
if ( mCanvas ->hasCrsTransformEnabled () && dprovider->crs () != mCanvas ->mapRenderer ()->destinationCrs () )
396
395
{
397
396
viewExtent = toLayerCoordinates ( layer, viewExtent );
398
- values = dprovider->identify ( point, format ). results ( );
397
+ identifyResult = dprovider->identify ( point, format );
399
398
}
400
399
else
401
400
{
@@ -418,106 +417,117 @@ bool QgsMapToolIdentify::identifyRasterLayer( QList<IdentifyResult> *results, Qg
418
417
QgsDebugMsg ( QString ( " width = %1 height = %2" ).arg ( width ).arg ( height ) );
419
418
QgsDebugMsg ( QString ( " xRes = %1 yRes = %2 mapUnitsPerPixel = %3" ).arg ( viewExtent.width () / width ).arg ( viewExtent.height () / height ).arg ( mapUnitsPerPixel ) );
420
419
421
- values = dprovider->identify ( point, format, viewExtent, width, height ). results ( );
420
+ identifyResult = dprovider->identify ( point, format, viewExtent, width, height );
422
421
}
423
422
424
423
derivedAttributes.insert ( tr ( " (clicked coordinate)" ), point.toString () );
425
424
426
- // QString type = tr( "Raster" );
427
- QgsGeometry geometry;
428
- if ( format == QgsRaster::IdentifyFormatValue )
425
+ if ( identifyResult.isValid () )
429
426
{
430
- foreach ( int bandNo, values.keys () )
427
+ QMap<int , QVariant> values = identifyResult.results ();
428
+ QgsGeometry geometry;
429
+ if ( format == QgsRaster::IdentifyFormatValue )
431
430
{
432
- QString valueString;
433
- if ( values.value ( bandNo ).isNull () )
434
- {
435
- valueString = tr ( " no data" );
436
- }
437
- else
431
+ foreach ( int bandNo, values.keys () )
438
432
{
439
- double value = values.value ( bandNo ).toDouble ();
440
- valueString = QgsRasterBlock::printValue ( value );
433
+ QString valueString;
434
+ if ( values.value ( bandNo ).isNull () )
435
+ {
436
+ valueString = tr ( " no data" );
437
+ }
438
+ else
439
+ {
440
+ double value = values.value ( bandNo ).toDouble ();
441
+ valueString = QgsRasterBlock::printValue ( value );
442
+ }
443
+ attributes.insert ( dprovider->generateBandName ( bandNo ), valueString );
441
444
}
442
- attributes.insert ( dprovider->generateBandName ( bandNo ), valueString );
445
+ QString label = layer->name ();
446
+ results->append ( IdentifyResult ( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
443
447
}
444
- QString label = layer->name ();
445
- results->append ( IdentifyResult ( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
446
- }
447
- else if ( format == QgsRaster::IdentifyFormatFeature )
448
- {
449
- foreach ( int i, values.keys () )
448
+ else if ( format == QgsRaster::IdentifyFormatFeature )
450
449
{
451
- QVariant value = values.value ( i );
452
- if ( value.type () == QVariant::Bool && !value.toBool () )
450
+ foreach ( int i, values.keys () )
453
451
{
454
- // sublayer not visible or not queryable
455
- continue ;
456
- }
452
+ QVariant value = values.value ( i );
453
+ if ( value.type () == QVariant::Bool && !value.toBool () )
454
+ {
455
+ // sublayer not visible or not queryable
456
+ continue ;
457
+ }
457
458
458
- if ( value.type () == QVariant::String )
459
- {
460
- // error
461
- // TODO: better error reporting
462
- QString label = layer->subLayers ().value ( i );
463
- attributes.clear ();
464
- attributes.insert ( tr ( " Error" ), value.toString () );
459
+ if ( value.type () == QVariant::String )
460
+ {
461
+ // error
462
+ // TODO: better error reporting
463
+ QString label = layer->subLayers ().value ( i );
464
+ attributes.clear ();
465
+ attributes.insert ( tr ( " Error" ), value.toString () );
465
466
466
- results->append ( IdentifyResult ( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
467
- continue ;
468
- }
467
+ results->append ( IdentifyResult ( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
468
+ continue ;
469
+ }
469
470
470
- // list of feature stores for a single sublayer
471
- QgsFeatureStoreList featureStoreList = values.value ( i ).value <QgsFeatureStoreList>();
471
+ // list of feature stores for a single sublayer
472
+ QgsFeatureStoreList featureStoreList = values.value ( i ).value <QgsFeatureStoreList>();
472
473
473
- foreach ( QgsFeatureStore featureStore, featureStoreList )
474
- {
475
- foreach ( QgsFeature feature, featureStore.features () )
474
+ foreach ( QgsFeatureStore featureStore, featureStoreList )
476
475
{
477
- attributes.clear ();
478
- // WMS sublayer and feature type, a sublayer may contain multiple feature types.
479
- // Sublayer name may be the same as layer name and feature type name
480
- // may be the same as sublayer. We try to avoid duplicities in label.
481
- QString sublayer = featureStore.params ().value ( " sublayer" ).toString ();
482
- QString featureType = featureStore.params ().value ( " featureType" ).toString ();
483
- // Strip UMN MapServer '_feature'
484
- featureType.remove ( " _feature" );
485
- QStringList labels;
486
- if ( sublayer.compare ( layer->name (), Qt::CaseInsensitive ) != 0 )
476
+ foreach ( QgsFeature feature, featureStore.features () )
487
477
{
488
- labels << sublayer;
478
+ attributes.clear ();
479
+ // WMS sublayer and feature type, a sublayer may contain multiple feature types.
480
+ // Sublayer name may be the same as layer name and feature type name
481
+ // may be the same as sublayer. We try to avoid duplicities in label.
482
+ QString sublayer = featureStore.params ().value ( " sublayer" ).toString ();
483
+ QString featureType = featureStore.params ().value ( " featureType" ).toString ();
484
+ // Strip UMN MapServer '_feature'
485
+ featureType.remove ( " _feature" );
486
+ QStringList labels;
487
+ if ( sublayer.compare ( layer->name (), Qt::CaseInsensitive ) != 0 )
488
+ {
489
+ labels << sublayer;
490
+ }
491
+ if ( featureType.compare ( sublayer, Qt::CaseInsensitive ) != 0 || labels.isEmpty () )
492
+ {
493
+ labels << featureType;
494
+
495
+
496
+ }
497
+
498
+ QMap< QString, QString > derAttributes = derivedAttributes;
499
+ derAttributes.unite ( featureDerivedAttributes ( &feature, layer ) );
500
+
501
+ IdentifyResult identifyResult ( qobject_cast<QgsMapLayer *>( layer ), labels.join ( " / " ), featureStore.fields (), feature, derAttributes );
502
+
503
+ identifyResult.mParams .insert ( " getFeatureInfoUrl" , featureStore.params ().value ( " getFeatureInfoUrl" ) );
504
+ results->append ( identifyResult );
489
505
}
490
- if ( featureType.compare ( sublayer, Qt::CaseInsensitive ) != 0 || labels.isEmpty () )
491
- {
492
- labels << featureType;
493
-
494
-
495
- }
496
-
497
- QMap< QString, QString > derAttributes = derivedAttributes;
498
- derAttributes.unite ( featureDerivedAttributes ( &feature, layer ) );
499
-
500
- IdentifyResult identifyResult ( qobject_cast<QgsMapLayer *>( layer ), labels.join ( " / " ), featureStore.fields (), feature, derAttributes );
501
-
502
- identifyResult.mParams .insert ( " getFeatureInfoUrl" , featureStore.params ().value ( " getFeatureInfoUrl" ) );
503
- results->append ( identifyResult );
504
506
}
505
507
}
506
508
}
507
- }
508
- else // text or html
509
- {
510
- QgsDebugMsg ( QString ( " %1 html or text values" ).arg ( values.size () ) );
511
- foreach ( int bandNo, values.keys () )
509
+ else // text or html
512
510
{
513
- QString value = values.value ( bandNo ).toString ();
514
- attributes.clear ();
515
- attributes.insert ( " " , value );
511
+ QgsDebugMsg ( QString ( " %1 html or text values" ).arg ( values.size () ) );
512
+ foreach ( int bandNo, values.keys () )
513
+ {
514
+ QString value = values.value ( bandNo ).toString ();
515
+ attributes.clear ();
516
+ attributes.insert ( " " , value );
516
517
517
- QString label = layer->subLayers ().value ( bandNo );
518
- results->append ( IdentifyResult ( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
518
+ QString label = layer->subLayers ().value ( bandNo );
519
+ results->append ( IdentifyResult ( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
520
+ }
519
521
}
520
522
}
523
+ else
524
+ {
525
+ attributes.clear ();
526
+ QString value = identifyResult.error ().message ( QgsErrorMessage::Text );
527
+ attributes.insert ( tr ( " Error" ), value );
528
+ QString label = tr ( " Identify error" );
529
+ results->append ( IdentifyResult ( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
530
+ }
521
531
522
532
return true ;
523
533
}
0 commit comments