Skip to content

Commit 96b3697

Browse files
author
morb_au
committed
More WMS improvements:
* The "Identify" map tool now works on queryable map layers. * The raster Properties/Metadata tab now shows if layers are queryable or not. Errors fixed: * Raster Properties/Metadata no longer repeats the details per layer. Errors known: * Layers that are non-queryable are not tested for when the Identify tool is invoked - the WMS server has to report the error instead. * The pixel identified is not highlighted. * Errors are not handled correctly; the window appears but no useful information is shown. git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5066 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 214914c commit 96b3697

7 files changed

+449
-133
lines changed

src/core/qgsrasterdataprovider.h

+15
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,21 @@ class QgsRasterDataProvider : public QgsDataProvider
9393
*/
9494
virtual QString getMetadata() = 0;
9595

96+
/**
97+
* \brief Identify details from a server (e.g. WMS) from the last screen update
98+
*
99+
* \param point[in] The pixel coordinate (as it was displayed locally on screen)
100+
*
101+
* \retval An HTML document containing the return from the WMS server
102+
*
103+
* \note WMS Servers prefer to receive coordinates in image space, therefore
104+
* this function expects coordinates in that format.
105+
*
106+
* \note The arbitraryness of the returned document is enforced by WMS standards
107+
* up to at least v1.3.0
108+
*/
109+
virtual QString identifyAsHtml(const QgsPoint& point) = 0;
110+
96111
/**
97112
* \brief Returns the caption error text for the last error in this provider
98113
*

src/gui/qgsmaptoolidentify.cpp

+90-13
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
***************************************************************************/
1515
/* $Id$ */
1616

17+
#include "qgsmessageviewer.h"
1718
#include "qgsmaptoolidentify.h"
1819
#include "qgsmapcanvas.h"
1920
#include "qgsvectordataprovider.h"
@@ -30,10 +31,13 @@
3031
#include <QMessageBox>
3132
#include <QCursor>
3233
#include <QPixmap>
34+
#include <QObject>
3335

3436

3537
QgsMapToolIdentify::QgsMapToolIdentify(QgsMapCanvas* canvas)
36-
: QgsMapTool(canvas), mResults(NULL)
38+
: QgsMapTool(canvas),
39+
mResults(0),
40+
mViewer(0)
3741
{
3842
// set cursor
3943
QPixmap myIdentifyQPixmap = QPixmap((const char **) identify_cursor);
@@ -42,7 +46,15 @@ QgsMapToolIdentify::QgsMapToolIdentify(QgsMapCanvas* canvas)
4246

4347
QgsMapToolIdentify::~QgsMapToolIdentify()
4448
{
45-
delete mResults;
49+
if (mResults)
50+
{
51+
delete mResults;
52+
}
53+
54+
if (mViewer)
55+
{
56+
delete mViewer;
57+
}
4658
}
4759

4860
void QgsMapToolIdentify::canvasMoveEvent(QMouseEvent * e)
@@ -61,24 +73,38 @@ void QgsMapToolIdentify::canvasReleaseEvent(QMouseEvent * e)
6173

6274
if (layer)
6375
{
64-
// convert screen coordinates to map coordinates
65-
QgsPoint idPoint = mCanvas->getCoordinateTransform()->toMapCoordinates(e->x(), e->y());
66-
67-
if (layer->type() == QgsMapLayer::VECTOR)
76+
// In the special case of the WMS provider,
77+
// coordinates are sent back to the server as pixel coordinates
78+
// not the layer's native CRS. So identify on screen coordinates!
79+
if (
80+
(layer->type() == QgsMapLayer::RASTER)
81+
&&
82+
(dynamic_cast<QgsRasterLayer*>(layer)->providerKey() == "wms")
83+
)
6884
{
69-
identifyVectorLayer(dynamic_cast<QgsVectorLayer*>(layer), idPoint);
70-
}
71-
else if (layer->type() == QgsMapLayer::RASTER)
72-
{
73-
identifyRasterLayer(dynamic_cast<QgsRasterLayer*>(layer), idPoint);
85+
identifyRasterWmsLayer(dynamic_cast<QgsRasterLayer*>(layer), QgsPoint(e->x(), e->y()) );
7486
}
7587
else
7688
{
89+
// convert screen coordinates to map coordinates
90+
QgsPoint idPoint = mCanvas->getCoordinateTransform()->toMapCoordinates(e->x(), e->y());
91+
92+
if (layer->type() == QgsMapLayer::VECTOR)
93+
{
94+
identifyVectorLayer(dynamic_cast<QgsVectorLayer*>(layer), idPoint);
95+
}
96+
else if (layer->type() == QgsMapLayer::RASTER)
97+
{
98+
identifyRasterLayer(dynamic_cast<QgsRasterLayer*>(layer), idPoint);
99+
}
100+
else
101+
{
77102
#ifdef QGISDEBUG
78-
std::cout << "identify: unknown layer type!" << std::endl;
103+
std::cout << "QgsMapToolIdentify::canvasReleaseEvent: unknown layer type!" << std::endl;
79104
#endif
105+
}
80106
}
81-
107+
82108
}
83109
else
84110
{
@@ -124,6 +150,34 @@ void QgsMapToolIdentify::identifyRasterLayer(QgsRasterLayer* layer, const QgsPoi
124150
}
125151

126152

153+
void QgsMapToolIdentify::identifyRasterWmsLayer(QgsRasterLayer* layer, const QgsPoint& point)
154+
{
155+
if (!layer)
156+
{
157+
return;
158+
}
159+
160+
QString html = layer->identifyAsHtml(point);
161+
162+
if (html.isEmpty())
163+
{
164+
showError(layer);
165+
return;
166+
}
167+
168+
if (!mViewer)
169+
{
170+
mViewer = new QgsMessageViewer();
171+
}
172+
173+
mViewer->setCaption( layer->name() );
174+
mViewer->setMessageAsPlainText( html );
175+
// mViewer->setMessageAsHtml( html );
176+
177+
// mViewer->exec();
178+
mViewer->show();
179+
}
180+
127181

128182
void QgsMapToolIdentify::identifyVectorLayer(QgsVectorLayer* layer, const QgsPoint& point)
129183
{
@@ -313,3 +367,26 @@ void QgsMapToolIdentify::identifyVectorLayer(QgsVectorLayer* layer, const QgsPoi
313367
}
314368
dataProvider->reset();
315369
}
370+
371+
372+
void QgsMapToolIdentify::showError(QgsMapLayer * mapLayer)
373+
{
374+
// QMessageBox::warning(
375+
// this,
376+
// mapLayer->errorCaptionString(),
377+
// tr("Could not draw") + " " + mapLayer->name() + " " + tr("because") + ":\n" +
378+
// mapLayer->errorString()
379+
// );
380+
381+
QgsMessageViewer * mv = new QgsMessageViewer();
382+
mv->setCaption( mapLayer->errorCaptionString() );
383+
mv->setMessageAsPlainText(
384+
QObject::tr("Could not identify objects on") + " " + mapLayer->name() + " " + QObject::tr("because") + ":\n" +
385+
mapLayer->errorString()
386+
);
387+
mv->exec();
388+
delete mv;
389+
390+
}
391+
392+
// ENDS

src/gui/qgsmaptoolidentify.h

+40-13
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@
2323
#define MapTool_Identify "identify"
2424

2525
class QgsIdentifyResults;
26+
class QgsMessageViewer;
27+
class QgsMapLayer;
2628
class QgsRasterLayer;
2729
class QgsVectorLayer;
2830

2931
/**
3032
\brief Map tool for identifying features in current layer
31-
33+
3234
after selecting a point shows dialog with identification results
3335
- for raster layers shows value of underlying pixel
3436
- for vector layers shows feature attributes within search radius
@@ -38,31 +40,56 @@ class QgsMapToolIdentify : public QgsMapTool
3840
{
3941
public:
4042
QgsMapToolIdentify(QgsMapCanvas* canvas);
41-
43+
4244
~QgsMapToolIdentify();
43-
45+
4446
//! Overridden mouse move event
4547
virtual void canvasMoveEvent(QMouseEvent * e);
46-
48+
4749
//! Overridden mouse press event
4850
virtual void canvasPressEvent(QMouseEvent * e);
49-
51+
5052
//! Overridden mouse release event
5153
virtual void canvasReleaseEvent(QMouseEvent * e);
52-
54+
5355
virtual QString toolName() { return MapTool_Identify; }
54-
56+
5557
private:
56-
57-
//! function for identifying raster layer
58+
59+
/**
60+
* \brief function for identifying pixel values at a coordinate in a non-OGC-WMS raster layer
61+
*
62+
* \param point[in] The coordinate (as the CRS of the raster layer)
63+
*/
5864
void identifyRasterLayer(QgsRasterLayer* layer, const QgsPoint& point);
59-
60-
//! function for identifying vector layer
65+
66+
/**
67+
* \brief function for identifying a pixel in a OGC WMS raster layer
68+
*
69+
* \param point[in] The pixel coordinate (as it was displayed locally on screen)
70+
*
71+
* \note WMS Servers prefer to receive coordinates in image space not CRS space, therefore
72+
* this special variant of identifyRasterLayer.
73+
*/
74+
void identifyRasterWmsLayer(QgsRasterLayer* layer, const QgsPoint& point);
75+
76+
/**
77+
* \brief function for identifying features at a coordinate in a vector layer
78+
*
79+
* \param point[in] The coordinate (as the CRS of the vector layer)
80+
*/
6181
void identifyVectorLayer(QgsVectorLayer* layer, const QgsPoint& point);
6282

63-
//! Pointer to the identify results dialog
83+
//! show whatever error is exposed by the QgsMapLayer.
84+
void showError(QgsMapLayer * mapLayer);
85+
86+
87+
//! Pointer to the identify results dialog for name/value pairs
6488
QgsIdentifyResults *mResults;
65-
89+
90+
//! Pointer to the identify results dialog for WMS XML files
91+
QgsMessageViewer * mViewer;
92+
6693
};
6794

6895
#endif

0 commit comments

Comments
 (0)