QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
Loading...
Searching...
No Matches
qgsmaptoolidentify.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsmaptoolidentify.h - map tool for identifying features
3 ---------------------
4 begin : January 2006
5 copyright : (C) 2006 by Martin Dobias
6 email : wonder.sk at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSMAPTOOLIDENTIFY_H
17#define QGSMAPTOOLIDENTIFY_H
18
19#include "qgis_gui.h"
20#include "qgsfeature.h"
21#include "qgsfields.h"
22#include "qgsidentifycontext.h"
23#include "qgsmaptool.h"
24#include "qgspointxy.h"
25
26#include <QObject>
27#include <QPointer>
28
29class QgsRasterLayer;
30class QgsVectorLayer;
32class QgsMapLayer;
33class QgsMapCanvas;
34class QgsMeshLayer;
35class QgsHighlight;
36class QgsIdentifyMenu;
42
53class GUI_EXPORT QgsMapToolIdentify : public QgsMapTool
54{
55 Q_OBJECT
56
57 public:
66 Q_ENUM( IdentifyMode )
67
77 Q_DECLARE_FLAGS( LayerType, Type )
78 Q_FLAG( LayerType )
79
81 {
82 IdentifyResult() = default;
83
84 IdentifyResult( QgsMapLayer *layer, const QgsFeature &feature, const QMap<QString, QString> &derivedAttributes )
85 : mLayer( layer )
86 , mFeature( feature )
87 , mDerivedAttributes( derivedAttributes )
88 {}
89
90 IdentifyResult( QgsMapLayer *layer, const QString &label, const QMap<QString, QString> &attributes, const QMap<QString, QString> &derivedAttributes )
91 : mLayer( layer )
92 , mLabel( label )
93 , mAttributes( attributes )
94 , mDerivedAttributes( derivedAttributes )
95 {}
96
97 IdentifyResult( QgsMapLayer *layer, const QString &label, const QgsFields &fields, const QgsFeature &feature, const QMap<QString, QString> &derivedAttributes )
98 : mLayer( layer )
99 , mLabel( label )
100 , mFields( fields )
101 , mFeature( feature )
102 , mDerivedAttributes( derivedAttributes )
103 {}
104
105 QgsMapLayer *mLayer = nullptr;
106 QString mLabel;
109 QMap<QString, QString> mAttributes;
110 QMap<QString, QString> mDerivedAttributes;
111 QMap<QString, QVariant> mParams;
112 };
113
115 {
119 bool skip3DLayers = false;
120 };
121
124
125 ~QgsMapToolIdentify() override;
126
127 Flags flags() const override { return QgsMapTool::AllowZoomRect; }
128 void canvasMoveEvent( QgsMapMouseEvent *e ) override;
129 void canvasPressEvent( QgsMapMouseEvent *e ) override;
130 void canvasReleaseEvent( QgsMapMouseEvent *e ) override;
131 void activate() override;
132 void deactivate() override;
133
143 QList<QgsMapToolIdentify::IdentifyResult> identify(
144 int x, int y, const QList<QgsMapLayer *> &layerList = QList<QgsMapLayer *>(), IdentifyMode mode = DefaultQgsSetting, const QgsIdentifyContext &identifyContext = QgsIdentifyContext()
145 );
146
158 QList<QgsMapToolIdentify::IdentifyResult> identify( int x, int y, IdentifyMode mode, LayerType layerType = AllLayers, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
159
161 QList<QgsMapToolIdentify::IdentifyResult> identify( const QgsGeometry &geometry, IdentifyMode mode, LayerType layerType, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
163 QList<QgsMapToolIdentify::IdentifyResult> identify(
164 const QgsGeometry &geometry, IdentifyMode mode, const QList<QgsMapLayer *> &layerList, LayerType layerType, const QgsIdentifyContext &identifyContext = QgsIdentifyContext()
165 );
166
167
173
179 static void fromPointCloudIdentificationToIdentifyResults( QgsPointCloudLayer *layer, const QVector<QVariantMap> &identified, QList<QgsMapToolIdentify::IdentifyResult> &results ) SIP_SKIP;
180
187 void fromElevationProfileLayerIdentificationToIdentifyResults( QgsMapLayer *layer, const QVector<QVariantMap> &identified, QList<QgsMapToolIdentify::IdentifyResult> &results ) SIP_SKIP;
188
189 public slots:
190 void formatChanged( QgsRasterLayer *layer );
191
192 signals:
193
200 void identifyProgress( int processed, int total );
201
207 void identifyMessage( const QString &message );
208
212 void changedRasterResults( QList<QgsMapToolIdentify::IdentifyResult> &results );
213
214 protected:
227 QList<QgsMapToolIdentify::IdentifyResult> identify(
228 int x, int y, IdentifyMode mode, const QList<QgsMapLayer *> &layerList, LayerType layerType = AllLayers, const QgsIdentifyContext &identifyContext = QgsIdentifyContext()
229 );
230
232
234 bool identifyLayer(
235 QList<QgsMapToolIdentify::IdentifyResult> *results,
237 const QgsPointXY &point,
238 const QgsRectangle &viewExtent,
239 double mapUnitsPerPixel,
241 const QgsIdentifyContext &identifyContext = QgsIdentifyContext()
242 );
243
254 QList<QgsMapToolIdentify::IdentifyResult> *results,
256 QgsPointXY point,
257 const QgsRectangle &viewExtent,
258 double mapUnitsPerPixel,
259 const QgsIdentifyContext &identifyContext = QgsIdentifyContext()
260 );
261
269 bool identifyVectorLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsVectorLayer *layer, const QgsPointXY &point, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
270
277 bool identifyMeshLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsMeshLayer *layer, const QgsPointXY &point, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
278
280 QMap<QString, QString> derivedAttributesForPoint( const QgsPoint &point );
281
296 Q_DECL_DEPRECATED void setCanvasPropertiesOverrides( double searchRadiusMapUnits ) SIP_DEPRECATED;
297
304 Q_DECL_DEPRECATED void restoreCanvasPropertiesOverrides() SIP_DEPRECATED;
305
319
326
327 private:
328 bool identifyLayer(
329 QList<QgsMapToolIdentify::IdentifyResult> *results,
331 const QgsGeometry &geometry,
332 const QgsRectangle &viewExtent,
333 double mapUnitsPerPixel,
335 const QgsIdentifyContext &identifyContext = QgsIdentifyContext()
336 );
338 QList<QgsMapToolIdentify::IdentifyResult> *results,
340 const QgsGeometry &geometry,
341 const QgsRectangle &viewExtent,
342 double mapUnitsPerPixel,
343 const QgsIdentifyContext &identifyContext = QgsIdentifyContext()
344 );
345 bool identifyVectorLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsVectorLayer *layer, const QgsGeometry &geometry, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
347 QList<QgsMapToolIdentify::IdentifyResult> *results,
349 const QgsFeatureList &features,
350 QgsFeatureRenderer *renderer,
351 const QMap<QString, QString> &commonDerivedAttributes,
352 const std::function<QMap<QString, QString>( const QgsFeature & )> &derivedAttributes,
353 QgsRenderContext &context
354 );
355 bool identifyMeshLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsMeshLayer *layer, const QgsGeometry &geometry, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
356 bool identifyVectorTileLayer(
357 QList<QgsMapToolIdentify::IdentifyResult> *results, QgsVectorTileLayer *layer, const QgsGeometry &geometry, const QgsIdentifyContext &identifyContext = QgsIdentifyContext()
358 );
359 bool identifyPointCloudLayer(
360 QList<QgsMapToolIdentify::IdentifyResult> *results, QgsPointCloudLayer *layer, const QgsGeometry &geometry, const QgsIdentifyContext &identifyContext = QgsIdentifyContext()
361 );
362
367 virtual Qgis::DistanceUnit displayDistanceUnits() const;
368
373 virtual Qgis::AreaUnit displayAreaUnits() const;
374
379 QString formatDistance( double distance ) const;
380
385 QString formatArea( double area ) const;
386
391 QString formatDistance( double distance, Qgis::DistanceUnit unit ) const;
392
397 QString formatArea( double area, Qgis::AreaUnit unit ) const;
398
399 QMap<QString, QString> featureDerivedAttributes( const QgsFeature &feature, QgsMapLayer *layer, const QgsPointXY &layerPoint = QgsPointXY() );
400
404 void closestVertexAttributes(
405 const QgsCoordinateTransform layerToMapTransform,
406 const QgsCoordinateReferenceSystem &layerVertCrs,
407 const QgsCoordinateReferenceSystem &mapVertCrs,
408 const QgsAbstractGeometry &geometry,
409 QgsVertexId vId,
410 bool showTransformedZ,
411 QMap<QString, QString> &derivedAttributes
412 );
413
417 void closestPointAttributes(
418 const QgsCoordinateTransform layerToMapTransform,
419 const QgsCoordinateReferenceSystem &layerVertCrs,
420 const QgsCoordinateReferenceSystem &mapVertCrs,
421 const QgsAbstractGeometry &geometry,
422 const QgsPointXY &layerPoint,
423 bool showTransformedZ,
424 QMap<QString, QString> &derivedAttributes
425 );
426
427 static void formatCoordinate( const QgsPointXY &canvasPoint, QString &x, QString &y, const QgsCoordinateReferenceSystem &mapCrs, int coordinatePrecision );
428 void formatCoordinate( const QgsPointXY &canvasPoint, QString &x, QString &y ) const;
429
430 // Last geometry (point or polygon) in map CRS
431 QgsGeometry mLastGeometry;
432
433 double mLastMapUnitsPerPixel = -1.0;
434
435 QgsRectangle mLastExtent;
436
437 int mCoordinatePrecision = 6;
438
439 IdentifyProperties mPropertiesOverrides;
440};
441
443
444#endif
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:62
Abstract base class for all geometries.
Represents a coordinate reference system (CRS).
Handles coordinate transforms between two coordinate systems.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Abstract base class for all 2D vector feature renderers.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:60
Container of fields for a vector layer.
Definition qgsfields.h:46
A geometry is the spatial representation of a feature.
Highlights features on the map.
Identify contexts are used to encapsulate the settings to be used to perform an identify action.
Builds a menu to be used with identify results.
Map canvas is a class for displaying all GIS data types on a canvas.
Base class for all map layer types.
Definition qgsmaplayer.h:83
A mouse event which is the result of a user interaction with a QgsMapCanvas.
QFlags< Type > LayerType
QgsIdentifyMenu * identifyMenu()
Returns a pointer to the identify menu which will be used in layer selection mode this menu can also ...
QMap< QString, QString > derivedAttributesForPoint(const QgsPoint &point)
Returns derived attributes map for a clicked point in map coordinates. May be 2D or 3D point.
bool identifyLayer(QList< QgsMapToolIdentify::IdentifyResult > *results, QgsMapLayer *layer, const QgsPointXY &point, const QgsRectangle &viewExtent, double mapUnitsPerPixel, QgsMapToolIdentify::LayerType layerType=AllLayers, const QgsIdentifyContext &identifyContext=QgsIdentifyContext())
Call the right method depending on layer type.
QList< QgsMapToolIdentify::IdentifyResult > identify(int x, int y, const QList< QgsMapLayer * > &layerList=QList< QgsMapLayer * >(), IdentifyMode mode=DefaultQgsSetting, const QgsIdentifyContext &identifyContext=QgsIdentifyContext())
Performs the identification.
void identifyMessage(const QString &message)
Emitted when the identify operation needs to show a user-facing message.
void restorePropertiesOverrides()
Clears canvas properties overrides previously set with setPropertiesOverrides().
Q_DECL_DEPRECATED void setCanvasPropertiesOverrides(double searchRadiusMapUnits)
Overrides some map canvas properties inside the map tool for the upcoming identify requests.
QgsMapToolIdentify(QgsMapCanvas *canvas)
constructor
void changedRasterResults(QList< QgsMapToolIdentify::IdentifyResult > &results)
Emitted when the format of raster results is changed and need to be updated in user-facing displays.
bool identifyRasterLayer(QList< QgsMapToolIdentify::IdentifyResult > *results, QgsRasterLayer *layer, QgsPointXY point, const QgsRectangle &viewExtent, double mapUnitsPerPixel, const QgsIdentifyContext &identifyContext=QgsIdentifyContext())
Performs the identification against a given raster layer.
bool identifyMeshLayer(QList< QgsMapToolIdentify::IdentifyResult > *results, QgsMeshLayer *layer, const QgsPointXY &point, const QgsIdentifyContext &identifyContext=QgsIdentifyContext())
Identifies data from active scalar and vector dataset from the mesh layer.
QgsIdentifyMenu * mIdentifyMenu
Flags flags() const override
Returns the flags for the map tool.
bool identifyVectorLayer(QList< QgsMapToolIdentify::IdentifyResult > *results, QgsVectorLayer *layer, const QgsPointXY &point, const QgsIdentifyContext &identifyContext=QgsIdentifyContext())
Performs the identification against a given vector layer.
void identifyProgress(int processed, int total)
Emitted when the identify action progresses.
Q_DECL_DEPRECATED void restoreCanvasPropertiesOverrides()
Clears canvas properties overrides previously set with setCanvasPropertiesOverrides().
void setPropertiesOverrides(IdentifyProperties overrides)
Overrides some map canvas properties inside the map tool for the upcoming identify requests.
QgsMapLayer * layer(const QString &id)
Returns the map layer with the matching ID, or nullptr if no layers could be found.
QgsMapCanvas * canvas() const
returns pointer to the tool's map canvas
QgsMapTool(QgsMapCanvas *canvas)
Constructor takes a map canvas as a parameter.
QFlags< Flag > Flags
Definition qgsmaptool.h:115
friend class QgsMapCanvas
Definition qgsmaptool.h:389
virtual void canvasPressEvent(QgsMapMouseEvent *e)
Mouse press event for overriding. Default implementation does nothing.
virtual void canvasMoveEvent(QgsMapMouseEvent *e)
Mouse move event for overriding. Default implementation does nothing.
virtual void canvasReleaseEvent(QgsMapMouseEvent *e)
Mouse release event for overriding. Default implementation does nothing.
@ AllowZoomRect
Allow zooming by rectangle (by holding shift and dragging) while the tool is active.
Definition qgsmaptool.h:112
virtual void activate()
called when set as currently active map tool
virtual void deactivate()
called when map tool is being deactivated
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Point cloud layer specific subclass of QgsMapLayerElevationProperties.
Represents a map layer supporting display of point clouds.
Represents a 2D point.
Definition qgspointxy.h:62
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:53
Represents a raster layer.
A rectangle specified with double values.
Contains information about the context of a rendering operation.
Represents a vector layer which manages a vector based dataset.
Implements a map layer that is dedicated to rendering of vector tiles.
#define SIP_DEPRECATED
Definition qgis_sip.h:113
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:274
#define SIP_SKIP
Definition qgis_sip.h:133
QList< QgsFeature > QgsFeatureList
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsProjectionSelectionWidget::CrsOptions)
double searchRadiusMapUnits
Identify search radius is map units. Use negative value to ignore.
bool skip3DLayers
Skip identify results from layers that have a 3d renderer set.
IdentifyResult(QgsMapLayer *layer, const QgsFeature &feature, const QMap< QString, QString > &derivedAttributes)
IdentifyResult(QgsMapLayer *layer, const QString &label, const QgsFields &fields, const QgsFeature &feature, const QMap< QString, QString > &derivedAttributes)
QMap< QString, QString > mDerivedAttributes
IdentifyResult(QgsMapLayer *layer, const QString &label, const QMap< QString, QString > &attributes, const QMap< QString, QString > &derivedAttributes)
Utility class for identifying a unique vertex within a geometry.
Definition qgsvertexid.h:34