@@ -1403,6 +1403,7 @@ int QgsWMSServer::getFeatureInfo( QDomDocument& result, QString version )
1403
1403
1404
1404
QgsRectangle* featuresRect = 0 ;
1405
1405
QgsPoint* infoPoint = 0 ;
1406
+
1406
1407
if ( i == -1 || j == -1 )
1407
1408
{
1408
1409
if ( mParameters .contains ( " FILTER" ) )
@@ -1416,7 +1417,11 @@ int QgsWMSServer::getFeatureInfo( QDomDocument& result, QString version )
1416
1417
}
1417
1418
else
1418
1419
{
1419
- infoPoint = new QgsPoint ();
1420
+ infoPoint = new QgsPoint ();
1421
+ if ( !infoPointToMapCoordinates ( i, j, infoPoint, mMapRenderer ) )
1422
+ {
1423
+ return 5 ;
1424
+ }
1420
1425
}
1421
1426
1422
1427
// get the layer registered in QgsMapLayerRegistry and apply possible filters
@@ -1501,11 +1506,6 @@ int QgsWMSServer::getFeatureInfo( QDomDocument& result, QString version )
1501
1506
continue ;
1502
1507
}
1503
1508
1504
- if ( infoPoint && infoPointToLayerCoordinates ( i, j, infoPoint, mMapRenderer , currentLayer ) != 0 )
1505
- {
1506
- continue ;
1507
- }
1508
-
1509
1509
// switch depending on vector or raster
1510
1510
QgsVectorLayer* vectorLayer = dynamic_cast <QgsVectorLayer*>( currentLayer );
1511
1511
@@ -1552,7 +1552,12 @@ int QgsWMSServer::getFeatureInfo( QDomDocument& result, QString version )
1552
1552
QgsRasterLayer* rasterLayer = dynamic_cast <QgsRasterLayer*>( currentLayer );
1553
1553
if ( rasterLayer )
1554
1554
{
1555
- if ( featureInfoFromRasterLayer ( rasterLayer, infoPoint, result, layerElement, version, infoFormat ) != 0 )
1555
+ if ( !infoPoint )
1556
+ {
1557
+ continue ;
1558
+ }
1559
+ QgsPoint layerInfoPoint = mMapRenderer ->mapToLayerCoordinates ( currentLayer, *infoPoint );
1560
+ if ( featureInfoFromRasterLayer ( rasterLayer, &layerInfoPoint, result, layerElement, version, infoFormat ) != 0 )
1556
1561
{
1557
1562
continue ;
1558
1563
}
@@ -1609,7 +1614,6 @@ int QgsWMSServer::getFeatureInfo( QDomDocument& result, QString version )
1609
1614
restoreLayerFilters ( originalLayerFilters );
1610
1615
QgsMapLayerRegistry::instance ()->removeAllMapLayers ();
1611
1616
delete featuresRect;
1612
- delete infoPoint;
1613
1617
return 0 ;
1614
1618
}
1615
1619
@@ -1916,38 +1920,18 @@ int QgsWMSServer::initializeSLDParser( QStringList& layersList, QStringList& sty
1916
1920
return 0 ;
1917
1921
}
1918
1922
1919
- int QgsWMSServer::infoPointToLayerCoordinates ( int i, int j, QgsPoint* layerCoords, QgsMapRenderer* mapRender,
1920
- QgsMapLayer* layer ) const
1923
+ bool QgsWMSServer::infoPointToMapCoordinates ( int i, int j, QgsPoint* infoPoint, QgsMapRenderer* mapRenderer )
1921
1924
{
1922
- if ( !layerCoords || !mapRender || !layer || !mapRender-> coordinateTransform () )
1925
+ if ( !mapRenderer || !infoPoint )
1923
1926
{
1924
- return 1 ;
1927
+ return false ;
1925
1928
}
1926
1929
1927
- // first transform i,j to map output coordinates
1928
- // toMapCoordinates() is currently (Oct 18 2012) using average resolution
1929
- // to calc point but GetFeatureInfo request may be sent with different
1930
- // resolutions in each axis
1931
- // QgsPoint mapPoint = mapRender->coordinateTransform()->toMapCoordinates( i, j );
1932
- double xRes = mapRender->extent ().width () / mapRender->width ();
1933
- double yRes = mapRender->extent ().height () / mapRender->height ();
1934
- QgsPoint mapPoint ( mapRender->extent ().xMinimum () + i * xRes,
1935
- mapRender->extent ().yMaximum () - j * yRes );
1936
-
1937
- QgsDebugMsg ( QString ( " mapPoint (corner): %1 %2" ).arg ( mapPoint.x () ).arg ( mapPoint.y () ) );
1938
- // use pixel center instead of corner
1939
- // Unfortunately going through pixel (integer) we cannot reconstruct precisely
1940
- // the coordinate clicked on client and thus result may differ from
1941
- // the same raster loaded and queried locally on client
1942
- mapPoint.setX ( mapPoint.x () + xRes / 2 );
1943
- mapPoint.setY ( mapPoint.y () - yRes / 2 );
1944
-
1945
- QgsDebugMsg ( QString ( " mapPoint (pixel center): %1 %2" ).arg ( mapPoint.x () ).arg ( mapPoint.y () ) );
1946
-
1947
- // and then to layer coordinates
1948
- *layerCoords = mapRender->mapToLayerCoordinates ( layer, mapPoint );
1949
- QgsDebugMsg ( QString ( " mapPoint: %1 %2" ).arg ( mapPoint.x () ).arg ( mapPoint.y () ) );
1950
- return 0 ;
1930
+ double xRes = mapRenderer->extent ().width () / mapRenderer->width ();
1931
+ double yRes = mapRenderer->extent ().height () / mapRenderer->height ();
1932
+ infoPoint->setX ( mapRenderer->extent ().xMinimum () + i * xRes + xRes / 2.0 );
1933
+ infoPoint->setY ( mapRenderer->extent ().yMaximum () - j * yRes - yRes / 2.0 );
1934
+ return true ;
1951
1935
}
1952
1936
1953
1937
int QgsWMSServer::featureInfoFromVectorLayer ( QgsVectorLayer* layer,
@@ -1970,27 +1954,13 @@ int QgsWMSServer::featureInfoFromVectorLayer( QgsVectorLayer* layer,
1970
1954
QgsRectangle mapRect = mapRender->extent ();
1971
1955
QgsRectangle layerRect = mapRender->mapToLayerCoordinates ( layer, mapRect );
1972
1956
1957
+
1973
1958
QgsRectangle searchRect;
1974
1959
1975
1960
// info point could be 0 in case there is only an attribute filter
1976
1961
if ( infoPoint )
1977
1962
{
1978
- double searchRadius = 0 ;
1979
- if ( layer->geometryType () == QGis::Polygon )
1980
- {
1981
- searchRadius = layerRect.width () / 400 ;
1982
- }
1983
- else if ( layer->geometryType () == QGis::Line )
1984
- {
1985
- searchRadius = layerRect.width () / 200 ;
1986
- }
1987
- else
1988
- {
1989
- searchRadius = layerRect.width () / 100 ;
1990
- }
1991
-
1992
- searchRect.set ( infoPoint->x () - searchRadius, infoPoint->y () - searchRadius,
1993
- infoPoint->x () + searchRadius, infoPoint->y () + searchRadius );
1963
+ searchRect = featureInfoSearchRect ( layer, mapRender, renderContext, *infoPoint );
1994
1964
}
1995
1965
else if ( mParameters .contains ( " BBOX" ) )
1996
1966
{
@@ -3112,3 +3082,53 @@ int QgsWMSServer::getWMSPrecision( int defaultValue = 8 ) const
3112
3082
}
3113
3083
return WMSPrecision;
3114
3084
}
3085
+
3086
+ QgsRectangle QgsWMSServer::featureInfoSearchRect ( QgsVectorLayer* ml, QgsMapRenderer* mr, const QgsRenderContext& rct, const QgsPoint& infoPoint ) const
3087
+ {
3088
+ if ( !ml || !mr )
3089
+ {
3090
+ return QgsRectangle ();
3091
+ }
3092
+
3093
+ double mapUnitTolerance = 0.0 ;
3094
+ if ( ml->geometryType () == QGis::Polygon )
3095
+ {
3096
+ QMap<QString, QString>::const_iterator tolIt = mParameters .find ( " POLYGON_TOLERANCE" );
3097
+ if ( tolIt != mParameters .constEnd () )
3098
+ {
3099
+ mapUnitTolerance = tolIt.value ().toInt () * rct.mapToPixel ().mapUnitsPerPixel ();
3100
+ }
3101
+ else
3102
+ {
3103
+ mapUnitTolerance = mr->extent ().width () / 400.0 ;
3104
+ }
3105
+ }
3106
+ else if ( ml->geometryType () == QGis::Line )
3107
+ {
3108
+ QMap<QString, QString>::const_iterator tolIt = mParameters .find ( " LINE_TOLERANCE" );
3109
+ if ( tolIt != mParameters .constEnd () )
3110
+ {
3111
+ mapUnitTolerance = tolIt.value ().toInt () * rct.mapToPixel ().mapUnitsPerPixel ();
3112
+ }
3113
+ else
3114
+ {
3115
+ mapUnitTolerance = mr->extent ().width () / 200.0 ;
3116
+ }
3117
+ }
3118
+ else // points
3119
+ {
3120
+ QMap<QString, QString>::const_iterator tolIt = mParameters .find ( " POINT_TOLERANCE" );
3121
+ if ( tolIt != mParameters .constEnd () )
3122
+ {
3123
+ mapUnitTolerance = tolIt.value ().toInt () * rct.mapToPixel ().mapUnitsPerPixel ();
3124
+ }
3125
+ else
3126
+ {
3127
+ mapUnitTolerance = mr->extent ().width () / 100.0 ;
3128
+ }
3129
+ }
3130
+
3131
+ QgsRectangle mapRectangle ( infoPoint.x () - mapUnitTolerance, infoPoint.y () - mapUnitTolerance,
3132
+ infoPoint.x () + mapUnitTolerance, infoPoint.y () + mapUnitTolerance );
3133
+ return ( mr->mapToLayerCoordinates ( ml, mapRectangle ) );
3134
+ }
0 commit comments