@@ -335,74 +335,45 @@ bool QgsMapToolIdentify::identifyRasterLayer( QgsRasterLayer *layer, int x, int
335
335
QgsDebugMsg ( QString ( " coordinate not reprojectable: %1" ).arg ( cse.what () ) );
336
336
return false ;
337
337
}
338
+ QgsDebugMsg ( QString ( " idPoint = %1 %2" ).arg ( idPoint.x () ).arg ( idPoint.y () ) );
338
339
339
340
if ( !layer->extent ().contains ( idPoint ) ) return false ;
340
341
341
- #if 0
342
- if ( layer->providerType() == "wms" )
343
- {
344
- type = tr( "WMS layer" );
345
-
346
- //if WMS layer does not cover the view origin,
347
- //we need to map the view pixel coordinates
348
- //to WMS layer pixel coordinates
349
- QgsRectangle viewExtent = toLayerCoordinates( layer, mCanvas->extent() );
350
- QgsRectangle layerExtent = layer->extent();
351
- double mapUnitsPerPixel = mCanvas->mapUnitsPerPixel();
352
- if ( mapUnitsPerPixel > 0 && viewExtent.intersects( layerExtent ) )
353
- {
354
- double xMinView = viewExtent.xMinimum();
355
- double yMaxView = viewExtent.yMaximum();
356
- double xMinLayer = layerExtent.xMinimum();
357
- double yMaxLayer = layerExtent.yMaximum();
358
-
359
- idPoint.set(
360
- xMinView < xMinLayer ? floor( x - ( xMinLayer - xMinView ) / mapUnitsPerPixel ) : x,
361
- yMaxView > yMaxLayer ? floor( y - ( yMaxView - yMaxLayer ) / mapUnitsPerPixel ) : y
362
- );
363
-
364
- attributes.insert( tr( "Feature info" ), layer->identifyAsHtml( idPoint ) );
365
- }
366
- else
367
- {
368
- res = false;
369
- }
370
- }
371
- #endif
342
+ QgsRectangle viewExtent = mCanvas ->extent ();
372
343
373
- // TODO: extent, width, heigh are approximated only if layer is reprojected!!!!
374
- // How to do it better? We dont know source resolution used to reproject the layer.
344
+ QMap< QString, QString > attributes, derivedAttributes;
375
345
376
- QgsRectangle viewExtent = mCanvas ->extent ();
346
+ // We can only use context (extent, width, heigh) if layer is not reprojected,
347
+ // otherwise we don't know source resolution (size).
377
348
if ( mCanvas ->hasCrsTransformEnabled () && dprovider->crs () != mCanvas ->mapRenderer ()->destinationCrs () )
378
349
{
379
350
viewExtent = toLayerCoordinates ( layer, viewExtent );
351
+ attributes = dprovider->identify ( idPoint );
380
352
}
353
+ else
354
+ {
355
+ // It would be nice to use the same extent and size which was used for drawing,
356
+ // so that WCS can use cache from last draw, unfortunately QgsRasterLayer::draw()
357
+ // is doing some tricks with extent and size to allign raster to output which
358
+ // would be difficult to replicate here.
359
+ // Note: cutting the extent may result in slightly different x and y resolutions
360
+ // and thus shifted point calculated back in QGIS WMS (using average resolution)
361
+ // viewExtent = dprovider->extent().intersect( &viewExtent );
381
362
382
- // It would be nice to use the same extent and size which was used for drawing,
383
- // so that WCS can use cache from last draw, unfortunately QgsRasterLayer::draw()
384
- // is doing some tricks with extent and size to allign raster to output which
385
- // would be difficult to replicate here.
386
- // Note: cutting the extent may result in slightly different x and y resolutions
387
- // and thus shifted point calculated back in QGIS WMS (using average resolution)
388
- // viewExtent = dprovider->extent().intersect( &viewExtent );
389
-
390
- double mapUnitsPerPixel = mCanvas ->mapUnitsPerPixel ();
391
- // Width and height are calculated from not projected extent and we hope that
392
- // are similar to source width and height used to reproject layer for drawing.
393
- // TODO: may be very dangerous, because it may result in different resolutions
394
- // in source CRS, and WMS server (QGIS server) calcs wrong coor using average resolution.
395
- int width = qRound ( viewExtent.width () / mapUnitsPerPixel );
396
- int height = qRound ( viewExtent.height () / mapUnitsPerPixel );
397
-
398
- QgsDebugMsg ( QString ( " viewExtent.width = %1 viewExtent.height = %2" ).arg ( viewExtent.width () ).arg ( viewExtent.height () ) );
399
- QgsDebugMsg ( QString ( " width = %1 height = %2" ).arg ( width ).arg ( height ) );
400
- QgsDebugMsg ( QString ( " xRes = %1 yRes = %2 mapUnitsPerPixel = %3" ).arg ( viewExtent.width () / width ).arg ( viewExtent.height () / height ).arg ( mapUnitsPerPixel ) );
401
-
402
- QMap< QString, QString > attributes, derivedAttributes;
403
-
404
- QgsDebugMsg ( QString ( " idPoint: %1 %2" ).arg ( idPoint.x () ).arg ( idPoint.y () ) );
405
- attributes = dprovider->identify ( idPoint, viewExtent, width, height );
363
+ double mapUnitsPerPixel = mCanvas ->mapUnitsPerPixel ();
364
+ // Width and height are calculated from not projected extent and we hope that
365
+ // are similar to source width and height used to reproject layer for drawing.
366
+ // TODO: may be very dangerous, because it may result in different resolutions
367
+ // in source CRS, and WMS server (QGIS server) calcs wrong coor using average resolution.
368
+ int width = qRound ( viewExtent.width () / mapUnitsPerPixel );
369
+ int height = qRound ( viewExtent.height () / mapUnitsPerPixel );
370
+
371
+ QgsDebugMsg ( QString ( " viewExtent.width = %1 viewExtent.height = %2" ).arg ( viewExtent.width () ).arg ( viewExtent.height () ) );
372
+ QgsDebugMsg ( QString ( " width = %1 height = %2" ).arg ( width ).arg ( height ) );
373
+ QgsDebugMsg ( QString ( " xRes = %1 yRes = %2 mapUnitsPerPixel = %3" ).arg ( viewExtent.width () / width ).arg ( viewExtent.height () / height ).arg ( mapUnitsPerPixel ) );
374
+
375
+ attributes = dprovider->identify ( idPoint, viewExtent, width, height );
376
+ }
406
377
407
378
QString type;
408
379
type = tr ( " Raster" );
0 commit comments