QGIS API Documentation 4.1.0-Master (467af3bbe65)
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;
38template<class T> class QgsSettingsEntryEnumFlag;
43
54class GUI_EXPORT QgsMapToolIdentify : public QgsMapTool
55{
56 Q_OBJECT
57
58 public:
67 Q_ENUM( IdentifyMode )
68
70
80 Q_DECLARE_FLAGS( LayerType, Type )
81 Q_FLAG( LayerType )
82
84 {
85 IdentifyResult() = default;
86
87 IdentifyResult( QgsMapLayer *layer, const QgsFeature &feature, const QMap<QString, QString> &derivedAttributes )
88 : mLayer( layer )
89 , mFeature( feature )
90 , mDerivedAttributes( derivedAttributes )
91 {}
92
93 IdentifyResult( QgsMapLayer *layer, const QString &label, const QMap<QString, QString> &attributes, const QMap<QString, QString> &derivedAttributes )
94 : mLayer( layer )
95 , mLabel( label )
96 , mAttributes( attributes )
97 , mDerivedAttributes( derivedAttributes )
98 {}
99
100 IdentifyResult( QgsMapLayer *layer, const QString &label, const QgsFields &fields, const QgsFeature &feature, const QMap<QString, QString> &derivedAttributes )
101 : mLayer( layer )
102 , mLabel( label )
103 , mFields( fields )
104 , mFeature( feature )
105 , mDerivedAttributes( derivedAttributes )
106 {}
107
108 QgsMapLayer *mLayer = nullptr;
109 QString mLabel;
112 QMap<QString, QString> mAttributes;
113 QMap<QString, QString> mDerivedAttributes;
114 QMap<QString, QVariant> mParams;
115 };
116
118 {
122 bool skip3DLayers = false;
123 };
124
127
128 ~QgsMapToolIdentify() override;
129
130 Flags flags() const override { return QgsMapTool::AllowZoomRect; }
131 void canvasMoveEvent( QgsMapMouseEvent *e ) override;
132 void canvasPressEvent( QgsMapMouseEvent *e ) override;
133 void canvasReleaseEvent( QgsMapMouseEvent *e ) override;
134 void activate() override;
135 void deactivate() override;
136
146 QList<QgsMapToolIdentify::IdentifyResult> identify(
147 int x, int y, const QList<QgsMapLayer *> &layerList = QList<QgsMapLayer *>(), IdentifyMode mode = DefaultQgsSetting, const QgsIdentifyContext &identifyContext = QgsIdentifyContext()
148 );
149
161 QList<QgsMapToolIdentify::IdentifyResult> identify( int x, int y, IdentifyMode mode, LayerType layerType = AllLayers, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
162
164 QList<QgsMapToolIdentify::IdentifyResult> identify( const QgsGeometry &geometry, IdentifyMode mode, LayerType layerType, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
166 QList<QgsMapToolIdentify::IdentifyResult> identify(
167 const QgsGeometry &geometry, IdentifyMode mode, const QList<QgsMapLayer *> &layerList, LayerType layerType, const QgsIdentifyContext &identifyContext = QgsIdentifyContext()
168 );
169
170
176
182 static void fromPointCloudIdentificationToIdentifyResults( QgsPointCloudLayer *layer, const QVector<QVariantMap> &identified, QList<QgsMapToolIdentify::IdentifyResult> &results ) SIP_SKIP;
183
190 void fromElevationProfileLayerIdentificationToIdentifyResults( QgsMapLayer *layer, const QVector<QVariantMap> &identified, QList<QgsMapToolIdentify::IdentifyResult> &results ) SIP_SKIP;
191
192 public slots:
193 void formatChanged( QgsRasterLayer *layer );
194
195 signals:
196
203 void identifyProgress( int processed, int total );
204
210 void identifyMessage( const QString &message );
211
215 void changedRasterResults( QList<QgsMapToolIdentify::IdentifyResult> &results );
216
217 protected:
230 QList<QgsMapToolIdentify::IdentifyResult> identify(
231 int x, int y, IdentifyMode mode, const QList<QgsMapLayer *> &layerList, LayerType layerType = AllLayers, const QgsIdentifyContext &identifyContext = QgsIdentifyContext()
232 );
233
235
237 bool identifyLayer(
238 QList<QgsMapToolIdentify::IdentifyResult> *results,
240 const QgsPointXY &point,
241 const QgsRectangle &viewExtent,
242 double mapUnitsPerPixel,
244 const QgsIdentifyContext &identifyContext = QgsIdentifyContext()
245 );
246
257 QList<QgsMapToolIdentify::IdentifyResult> *results,
259 QgsPointXY point,
260 const QgsRectangle &viewExtent,
261 double mapUnitsPerPixel,
262 const QgsIdentifyContext &identifyContext = QgsIdentifyContext()
263 );
264
272 bool identifyVectorLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsVectorLayer *layer, const QgsPointXY &point, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
273
280 bool identifyMeshLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsMeshLayer *layer, const QgsPointXY &point, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
281
283 QMap<QString, QString> derivedAttributesForPoint( const QgsPoint &point );
284
299 Q_DECL_DEPRECATED void setCanvasPropertiesOverrides( double searchRadiusMapUnits ) SIP_DEPRECATED;
300
307 Q_DECL_DEPRECATED void restoreCanvasPropertiesOverrides() SIP_DEPRECATED;
308
322
329
330 private:
331 bool identifyLayer(
332 QList<QgsMapToolIdentify::IdentifyResult> *results,
334 const QgsGeometry &geometry,
335 const QgsRectangle &viewExtent,
336 double mapUnitsPerPixel,
338 const QgsIdentifyContext &identifyContext = QgsIdentifyContext()
339 );
341 QList<QgsMapToolIdentify::IdentifyResult> *results,
343 const QgsGeometry &geometry,
344 const QgsRectangle &viewExtent,
345 double mapUnitsPerPixel,
346 const QgsIdentifyContext &identifyContext = QgsIdentifyContext()
347 );
348 bool identifyVectorLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsVectorLayer *layer, const QgsGeometry &geometry, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
350 QList<QgsMapToolIdentify::IdentifyResult> *results,
352 const QgsFeatureList &features,
353 QgsFeatureRenderer *renderer,
354 const QMap<QString, QString> &commonDerivedAttributes,
355 const std::function<QMap<QString, QString>( const QgsFeature & )> &derivedAttributes,
356 QgsRenderContext &context
357 );
358 bool identifyMeshLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsMeshLayer *layer, const QgsGeometry &geometry, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
359 bool identifyVectorTileLayer(
360 QList<QgsMapToolIdentify::IdentifyResult> *results, QgsVectorTileLayer *layer, const QgsGeometry &geometry, const QgsIdentifyContext &identifyContext = QgsIdentifyContext()
361 );
362 bool identifyPointCloudLayer(
363 QList<QgsMapToolIdentify::IdentifyResult> *results, QgsPointCloudLayer *layer, const QgsGeometry &geometry, const QgsIdentifyContext &identifyContext = QgsIdentifyContext()
364 );
365
370 virtual Qgis::DistanceUnit displayDistanceUnits() const;
371
376 virtual Qgis::AreaUnit displayAreaUnits() const;
377
382 QString formatDistance( double distance ) const;
383
388 QString formatArea( double area ) const;
389
394 QString formatDistance( double distance, Qgis::DistanceUnit unit ) const;
395
400 QString formatArea( double area, Qgis::AreaUnit unit ) const;
401
402 QMap<QString, QString> featureDerivedAttributes( const QgsFeature &feature, QgsMapLayer *layer, const QgsPointXY &layerPoint = QgsPointXY() );
403
407 void closestVertexAttributes(
408 const QgsCoordinateTransform layerToMapTransform,
409 const QgsCoordinateReferenceSystem &layerVertCrs,
410 const QgsCoordinateReferenceSystem &mapVertCrs,
411 const QgsAbstractGeometry &geometry,
412 QgsVertexId vId,
413 bool showTransformedZ,
414 QMap<QString, QString> &derivedAttributes
415 );
416
420 void closestPointAttributes(
421 const QgsCoordinateTransform layerToMapTransform,
422 const QgsCoordinateReferenceSystem &layerVertCrs,
423 const QgsCoordinateReferenceSystem &mapVertCrs,
424 const QgsAbstractGeometry &geometry,
425 const QgsPointXY &layerPoint,
426 bool showTransformedZ,
427 QMap<QString, QString> &derivedAttributes
428 );
429
430 static void formatCoordinate( const QgsPointXY &canvasPoint, QString &x, QString &y, const QgsCoordinateReferenceSystem &mapCrs, int coordinatePrecision );
431 void formatCoordinate( const QgsPointXY &canvasPoint, QString &x, QString &y ) const;
432
433 // Last geometry (point or polygon) in map CRS
434 QgsGeometry mLastGeometry;
435
436 double mLastMapUnitsPerPixel = -1.0;
437
438 QgsRectangle mLastExtent;
439
440 int mCoordinatePrecision = 6;
441
442 IdentifyProperties mPropertiesOverrides;
443};
444
446
447#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.
static const QgsSettingsEntryEnumFlag< IdentifyMode > * settingIdentifyMode
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:116
friend class QgsMapCanvas
Definition qgsmaptool.h:400
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:113
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.
A template class for enum and flag settings entry.
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