Skip to content

Commit

Permalink
identify context only if not projected
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Oct 19, 2012
1 parent f0a8c6d commit 675e81c
Showing 1 changed file with 29 additions and 58 deletions.
87 changes: 29 additions & 58 deletions src/app/qgsmaptoolidentify.cpp
Expand Up @@ -335,74 +335,45 @@ bool QgsMapToolIdentify::identifyRasterLayer( QgsRasterLayer *layer, int x, int
QgsDebugMsg( QString( "coordinate not reprojectable: %1" ).arg( cse.what() ) );
return false;
}
QgsDebugMsg( QString( "idPoint = %1 %2" ).arg( idPoint.x() ).arg( idPoint.y() ) );

if ( !layer->extent().contains( idPoint ) ) return false;

#if 0
if ( layer->providerType() == "wms" )
{
type = tr( "WMS layer" );

//if WMS layer does not cover the view origin,
//we need to map the view pixel coordinates
//to WMS layer pixel coordinates
QgsRectangle viewExtent = toLayerCoordinates( layer, mCanvas->extent() );
QgsRectangle layerExtent = layer->extent();
double mapUnitsPerPixel = mCanvas->mapUnitsPerPixel();
if ( mapUnitsPerPixel > 0 && viewExtent.intersects( layerExtent ) )
{
double xMinView = viewExtent.xMinimum();
double yMaxView = viewExtent.yMaximum();
double xMinLayer = layerExtent.xMinimum();
double yMaxLayer = layerExtent.yMaximum();

idPoint.set(
xMinView < xMinLayer ? floor( x - ( xMinLayer - xMinView ) / mapUnitsPerPixel ) : x,
yMaxView > yMaxLayer ? floor( y - ( yMaxView - yMaxLayer ) / mapUnitsPerPixel ) : y
);

attributes.insert( tr( "Feature info" ), layer->identifyAsHtml( idPoint ) );
}
else
{
res = false;
}
}
#endif
QgsRectangle viewExtent = mCanvas->extent();

// TODO: extent, width, heigh are approximated only if layer is reprojected!!!!
// How to do it better? We dont know source resolution used to reproject the layer.
QMap< QString, QString > attributes, derivedAttributes;

QgsRectangle viewExtent = mCanvas->extent();
// We can only use context (extent, width, heigh) if layer is not reprojected,
// otherwise we don't know source resolution (size).
if ( mCanvas->hasCrsTransformEnabled() && dprovider->crs() != mCanvas->mapRenderer()->destinationCrs() )
{
viewExtent = toLayerCoordinates( layer, viewExtent );
attributes = dprovider->identify( idPoint );
}
else
{
// It would be nice to use the same extent and size which was used for drawing,
// so that WCS can use cache from last draw, unfortunately QgsRasterLayer::draw()
// is doing some tricks with extent and size to allign raster to output which
// would be difficult to replicate here.
// Note: cutting the extent may result in slightly different x and y resolutions
// and thus shifted point calculated back in QGIS WMS (using average resolution)
//viewExtent = dprovider->extent().intersect( &viewExtent );

// It would be nice to use the same extent and size which was used for drawing,
// so that WCS can use cache from last draw, unfortunately QgsRasterLayer::draw()
// is doing some tricks with extent and size to allign raster to output which
// would be difficult to replicate here.
// Note: cutting the extent may result in slightly different x and y resolutions
// and thus shifted point calculated back in QGIS WMS (using average resolution)
//viewExtent = dprovider->extent().intersect( &viewExtent );

double mapUnitsPerPixel = mCanvas->mapUnitsPerPixel();
// Width and height are calculated from not projected extent and we hope that
// are similar to source width and height used to reproject layer for drawing.
// TODO: may be very dangerous, because it may result in different resolutions
// in source CRS, and WMS server (QGIS server) calcs wrong coor using average resolution.
int width = qRound( viewExtent.width() / mapUnitsPerPixel );
int height = qRound( viewExtent.height() / mapUnitsPerPixel );

QgsDebugMsg( QString( "viewExtent.width = %1 viewExtent.height = %2" ).arg( viewExtent.width() ).arg( viewExtent.height() ) );
QgsDebugMsg( QString( "width = %1 height = %2" ).arg( width ).arg( height ) );
QgsDebugMsg( QString( "xRes = %1 yRes = %2 mapUnitsPerPixel = %3" ).arg( viewExtent.width() / width ).arg( viewExtent.height() / height ).arg( mapUnitsPerPixel ) );

QMap< QString, QString > attributes, derivedAttributes;

QgsDebugMsg( QString( "idPoint: %1 %2" ).arg( idPoint.x() ).arg( idPoint.y() ) );
attributes = dprovider->identify( idPoint, viewExtent, width, height );
double mapUnitsPerPixel = mCanvas->mapUnitsPerPixel();
// Width and height are calculated from not projected extent and we hope that
// are similar to source width and height used to reproject layer for drawing.
// TODO: may be very dangerous, because it may result in different resolutions
// in source CRS, and WMS server (QGIS server) calcs wrong coor using average resolution.
int width = qRound( viewExtent.width() / mapUnitsPerPixel );
int height = qRound( viewExtent.height() / mapUnitsPerPixel );

QgsDebugMsg( QString( "viewExtent.width = %1 viewExtent.height = %2" ).arg( viewExtent.width() ).arg( viewExtent.height() ) );
QgsDebugMsg( QString( "width = %1 height = %2" ).arg( width ).arg( height ) );
QgsDebugMsg( QString( "xRes = %1 yRes = %2 mapUnitsPerPixel = %3" ).arg( viewExtent.width() / width ).arg( viewExtent.height() / height ).arg( mapUnitsPerPixel ) );

attributes = dprovider->identify( idPoint, viewExtent, width, height );
}

QString type;
type = tr( "Raster" );
Expand Down

0 comments on commit 675e81c

Please sign in to comment.