QGIS API Documentation 3.41.0-Master (af5edcb665c)
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 "qgsfeature.h"
20#include "qgsfields.h"
21#include "qgsidentifycontext.h"
22#include "qgsmaptool.h"
23#include "qgspointxy.h"
24
25#include <QObject>
26#include <QPointer>
27#include "qgis_gui.h"
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:
59 {
60 DefaultQgsSetting = -1,
64 LayerSelection
65 };
66 Q_ENUM( IdentifyMode )
67
68 enum Type SIP_ENUM_BASETYPE( IntFlag )
69 {
70 VectorLayer = 1,
71 RasterLayer = 2,
72 MeshLayer = 4,
73 VectorTileLayer = 8,
74 PointCloudLayer = 16,
75 AllLayers = VectorLayer | RasterLayer | MeshLayer | VectorTileLayer | PointCloudLayer
76 };
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 ), mFeature( feature ), mDerivedAttributes( derivedAttributes ) {}
86
87 IdentifyResult( QgsMapLayer *layer, const QString &label, const QMap<QString, QString> &attributes, const QMap<QString, QString> &derivedAttributes )
88 : mLayer( layer ), mLabel( label ), mAttributes( attributes ), mDerivedAttributes( derivedAttributes ) {}
89
90 IdentifyResult( QgsMapLayer *layer, const QString &label, const QgsFields &fields, const QgsFeature &feature, const QMap<QString, QString> &derivedAttributes )
91 : mLayer( layer ), mLabel( label ), mFields( fields ), mFeature( feature ), mDerivedAttributes( derivedAttributes ) {}
92
93 QgsMapLayer *mLayer = nullptr;
94 QString mLabel;
97 QMap<QString, QString> mAttributes;
98 QMap<QString, QString> mDerivedAttributes;
99 QMap<QString, QVariant> mParams;
100 };
101
104
105 ~QgsMapToolIdentify() override;
106
107 Flags flags() const override { return QgsMapTool::AllowZoomRect; }
108 void canvasMoveEvent( QgsMapMouseEvent *e ) override;
109 void canvasPressEvent( QgsMapMouseEvent *e ) override;
110 void canvasReleaseEvent( QgsMapMouseEvent *e ) override;
111 void activate() override;
112 void deactivate() override;
113
123 QList<QgsMapToolIdentify::IdentifyResult> identify( int x, int y, const QList<QgsMapLayer *> &layerList = QList<QgsMapLayer *>(), IdentifyMode mode = DefaultQgsSetting, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
124
136 QList<QgsMapToolIdentify::IdentifyResult> identify( int x, int y, IdentifyMode mode, LayerType layerType = AllLayers, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
137
139 QList<QgsMapToolIdentify::IdentifyResult> identify( const QgsGeometry &geometry, IdentifyMode mode, LayerType layerType, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
141 QList<QgsMapToolIdentify::IdentifyResult> identify( const QgsGeometry &geometry, IdentifyMode mode, const QList<QgsMapLayer *> &layerList, LayerType layerType, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
142
143
148 QgsIdentifyMenu *identifyMenu() { return mIdentifyMenu; }
149
155 static void fromPointCloudIdentificationToIdentifyResults( QgsPointCloudLayer *layer, const QVector<QVariantMap> &identified, QList<QgsMapToolIdentify::IdentifyResult> &results ) SIP_SKIP;
156
163 void fromElevationProfileLayerIdentificationToIdentifyResults( QgsMapLayer *layer, const QVector<QVariantMap> &identified, QList<QgsMapToolIdentify::IdentifyResult> &results ) SIP_SKIP;
164
165 public slots:
166 void formatChanged( QgsRasterLayer *layer );
167
168 signals:
169
176 void identifyProgress( int processed, int total );
177
183 void identifyMessage( const QString &message );
184
188 void changedRasterResults( QList<QgsMapToolIdentify::IdentifyResult> &results );
189
190 protected:
203 QList<QgsMapToolIdentify::IdentifyResult> identify( int x, int y, IdentifyMode mode, const QList<QgsMapLayer *> &layerList, LayerType layerType = AllLayers, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
204
205 QgsIdentifyMenu *mIdentifyMenu = nullptr;
206
208 bool identifyLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsMapLayer *layer, const QgsPointXY &point, const QgsRectangle &viewExtent, double mapUnitsPerPixel, QgsMapToolIdentify::LayerType layerType = AllLayers, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
209
219 bool identifyRasterLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsRasterLayer *layer, QgsPointXY point, const QgsRectangle &viewExtent, double mapUnitsPerPixel, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
220
228 bool identifyVectorLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsVectorLayer *layer, const QgsPointXY &point, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
229
236 bool identifyMeshLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsMeshLayer *layer, const QgsPointXY &point, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
237
239 QMap<QString, QString> derivedAttributesForPoint( const QgsPoint &point );
240
253 void setCanvasPropertiesOverrides( double searchRadiusMapUnits );
254
260 void restoreCanvasPropertiesOverrides();
261
262 private:
263 bool identifyLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsMapLayer *layer, const QgsGeometry &geometry, const QgsRectangle &viewExtent, double mapUnitsPerPixel, QgsMapToolIdentify::LayerType layerType = AllLayers, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
264 bool identifyRasterLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsRasterLayer *layer, const QgsGeometry &geometry, const QgsRectangle &viewExtent, double mapUnitsPerPixel, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
265 bool identifyVectorLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsVectorLayer *layer, const QgsGeometry &geometry, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
266 int identifyVectorLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsVectorLayer *layer, const QgsFeatureList &features, QgsFeatureRenderer *renderer, const QMap<QString, QString> &commonDerivedAttributes, const std::function<QMap<QString, QString>( const QgsFeature & )> &derivedAttributes, QgsRenderContext &context );
267 bool identifyMeshLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsMeshLayer *layer, const QgsGeometry &geometry, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
268 bool identifyVectorTileLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsVectorTileLayer *layer, const QgsGeometry &geometry, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
269 bool identifyPointCloudLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsPointCloudLayer *layer, const QgsGeometry &geometry, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
270
275 virtual Qgis::DistanceUnit displayDistanceUnits() const;
276
281 virtual Qgis::AreaUnit displayAreaUnits() const;
282
287 QString formatDistance( double distance ) const;
288
293 QString formatArea( double area ) const;
294
299 QString formatDistance( double distance, Qgis::DistanceUnit unit ) const;
300
305 QString formatArea( double area, Qgis::AreaUnit unit ) const;
306
307 QMap<QString, QString> featureDerivedAttributes( const QgsFeature &feature, QgsMapLayer *layer, const QgsPointXY &layerPoint = QgsPointXY() );
308
312 void closestVertexAttributes( const QgsCoordinateTransform layerToMapTransform, const QgsCoordinateReferenceSystem &layerVertCrs, const QgsCoordinateReferenceSystem &mapVertCrs, const QgsAbstractGeometry &geometry, QgsVertexId vId, bool showTransformedZ, QMap<QString, QString> &derivedAttributes );
313
317 void closestPointAttributes( const QgsCoordinateTransform layerToMapTransform, const QgsCoordinateReferenceSystem &layerVertCrs, const QgsCoordinateReferenceSystem &mapVertCrs, const QgsAbstractGeometry &geometry, const QgsPointXY &layerPoint, bool showTransformedZ, QMap<QString, QString> &derivedAttributes );
318
319 static void formatCoordinate( const QgsPointXY &canvasPoint, QString &x, QString &y, const QgsCoordinateReferenceSystem &mapCrs, int coordinatePrecision );
320 void formatCoordinate( const QgsPointXY &canvasPoint, QString &x, QString &y ) const;
321
322 // Last geometry (point or polygon) in map CRS
323 QgsGeometry mLastGeometry;
324
325 double mLastMapUnitsPerPixel;
326
327 QgsRectangle mLastExtent;
328
329 int mCoordinatePrecision;
330
331 double mOverrideCanvasSearchRadius = -1;
332};
333
335
336#endif
DistanceUnit
Units of distance.
Definition qgis.h:4740
AreaUnit
Units of area.
Definition qgis.h:4817
Abstract base class for all geometries.
This class represents a coordinate reference system (CRS).
Class for doing transforms between two map 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:58
Container of fields for a vector layer.
Definition qgsfields.h:46
A geometry is the spatial representation of a feature.
A class for highlight features on the map.
Identify contexts are used to encapsulate the settings to be used to perform an identify action.
The QgsIdentifyMenu class 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:76
A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas.
Map tool for identifying features in layers.
QFlags< Type > LayerType
QgsIdentifyMenu * identifyMenu()
Returns a pointer to the identify menu which will be used in layer selection mode this menu can also ...
void identifyMessage(const QString &message)
Emitted when the identify operation needs to show a user-facing message.
void changedRasterResults(QList< QgsMapToolIdentify::IdentifyResult > &results)
Emitted when the format of raster results is changed and need to be updated in user-facing displays.
Flags flags() const override
Returns the flags for the map tool.
void identifyProgress(int processed, int total)
Emitted when the identify action progresses.
Abstract base class for all map tools.
Definition qgsmaptool.h:71
QFlags< Flag > Flags
Definition qgsmaptool.h:114
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:111
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.
A class to represent a 2D point.
Definition qgspointxy.h:60
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:49
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 data sets.
Implements a map layer that is dedicated to rendering of vector tiles.
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:278
#define SIP_SKIP
Definition qgis_sip.h:126
QList< QgsFeature > QgsFeatureList
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsTextRendererUtils::CurvedTextFlags)
QMap< QString, QString > mAttributes
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, QVariant > mParams
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:30