53 QgsDebugMsg( QStringLiteral(
"Unable to use IdentifyKit without mapSettings property set." ) );
60 QgsFeatureList featureList = identifyVectorLayer( layer, mapPoint );
61 for (
const QgsFeature &feature : featureList )
65 QgsDebugMsg( QStringLiteral(
"IdentifyKit identified %1 results for layer %2" ).arg( results.count() ).arg( layer->
name() ) );
79 for (
const QgsFeature &feature : featureList )
84 if ( mIdentifyMode == IdentifyMode::TopDownStopAtFirst && !results.isEmpty() )
86 QgsDebugMsg( QStringLiteral(
"IdentifyKit identified %1 results with TopDownStopAtFirst mode." ).arg( results.count() ) );
91 QgsDebugMsg( QStringLiteral(
"IdentifyKit identified %1 results" ).arg( results.count() ) );
102 double distMinPoint = 1e10, distMinLine = 1e10, distMinPolygon = 1e10;
103 int iMinPoint = -1, iMinLine = -1, iMinPolygon = -1;
104 for (
int i = 0; i < results.count(); ++i )
119 double dist = geom.distance( mapPointGeom );
123 if ( dist < distMinPoint )
131 if ( dist < distMinLine )
139 if ( dist < distMinPolygon )
142 distMinPolygon = dist;
151 if ( iMinPoint != -1 && distMinPoint <= searchRadius )
152 return results.at( iMinPoint );
153 else if ( iMinLine != -1 && distMinLine <= searchRadius )
154 return results.at( iMinLine );
155 else if ( iMinPolygon != -1 )
156 return results.at( iMinPolygon );
164 return _closestFeature( results, mMapSettings->
mapSettings(), point, searchRadiusMU() );
185 double searchRadius = searchRadiusMU();
193 r = toLayerCoordinates( layer, r );
207 QgsDebugMsg( QStringLiteral(
"Invalid point, proceed without a found features." ) );
223 for (
const QgsFeature &feature : featureList )
225 context.expressionContext().setFeature( feature );
230 results.append( feature );
241 double QgsQuickIdentifyKit::searchRadiusMU(
const QgsRenderContext &context )
const
246 double QgsQuickIdentifyKit::searchRadiusMU()
const
249 return searchRadiusMU( context );
259 return mSearchRadiusMm;
273 return mFeaturesLimit;
278 if ( mFeaturesLimit == limit )
281 mFeaturesLimit = limit;
Custom exception class for Coordinate Reference System related exceptions.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
virtual void stopRender(QgsRenderContext &context)
Must be called when a render cycle has finished, to allow the renderer to clean up.
virtual QgsFeatureRenderer::Capabilities capabilities()
Returns details about internals of this renderer.
@ ScaleDependent
Depends on scale if feature will be rendered (rule based )
@ Filter
Features may be filtered, i.e. some features may not be rendered (categorized, rule based ....
virtual bool willRenderFeature(const QgsFeature &feature, QgsRenderContext &context) const
Returns whether the renderer will render a feature or not.
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)
Must be called when a new render cycle is started.
This class wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setFlags(QgsFeatureRequest::Flags flags)
Sets flags that affect how features will be fetched.
QgsFeatureRequest & setLimit(long limit)
Set the maximum number of features to request.
@ ExactIntersect
Use exact geometry intersection (slower) instead of bounding boxes.
QgsFeatureRequest & setFilterRect(const QgsRectangle &rectangle)
Sets the rectangle from which features will be taken.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
A geometry is the spatial representation of a feature.
static QgsGeometry fromPointXY(const QgsPointXY &point) SIP_HOLDGIL
Creates a new geometry from a QgsPointXY object.
Base class for all map layer types.
bool isInScaleRange(double scale) const
Tests whether the layer should be visible at the specified scale.
QgsMapLayer::LayerFlags flags() const
Returns the flags for this layer.
@ Identifiable
If the layer is identifiable using the identify map tool and as a WMS layer.
The QgsMapSettings class contains configuration for rendering of the map.
double scale() const
Returns the calculated map scale.
QgsCoordinateTransform layerTransform(const QgsMapLayer *layer) const
Returns the coordinate transform from layer's CRS to destination CRS.
const QgsMapToPixel & mapToPixel() const
QList< QgsMapLayer * > layers() const
Returns the list of layers which will be rendered in the map.
QgsPointXY mapToLayerCoordinates(const QgsMapLayer *layer, QgsPointXY point) const
transform point coordinates from output CRS to layer's CRS
double mapUnitsPerPixel() const
Returns current map units per pixel.
QgsPointXY toMapCoordinates(int x, int y) const
Transform device coordinates to map (world) coordinates.
A class to represent a 2D point.
Pair of QgsFeature and QgsVectorLayer.
QgsFeature feature
Feature that belongs to layer.
Q_GADGET QgsVectorLayer * layer
Vector layer to which the feature belongs.
void searchRadiusMmChanged()
Search radius for the identify functions.
void mapSettingsChanged()
Map settings.
int featuresLimit
Maximum number of features returned from the QgsQuickIdentifyKit::identify()
void setSearchRadiusMm(double searchRadiusMm)
Search radius for the identify functions.
void setFeaturesLimit(int limit)
Maximum number of features returned from the QgsQuickIdentifyKit::identify()
void featuresLimitChanged()
Maximum number of features returned from the QgsQuickIdentifyKit::identify()
QgsQuickMapSettings * mapSettings
Map settings.
QgsQuickIdentifyKit(QObject *parent=nullptr)
Constructor of new identify kit.
double searchRadiusMm
Search radius for the identify functions.
Q_INVOKABLE QgsQuickFeatureLayerPairs identify(const QPointF &point, QgsVectorLayer *layer=nullptr)
Gets all features in the search radius.
Q_INVOKABLE QgsQuickFeatureLayerPair identifyOne(const QPointF &point, QgsVectorLayer *layer=nullptr)
Gets the closest feature to the point within the search radius.
void setMapSettings(QgsQuickMapSettings *mapSettings)
Map settings.
The QgsQuickMapSettings class encapsulates QgsMapSettings class to offer settings of configuration of...
QgsMapSettings mapSettings() const
Clone map settings.
QgsProject * project
A project property should be used as a primary source of project all other components in the applicat...
A rectangle specified with double values.
void setYMinimum(double y) SIP_HOLDGIL
Set the minimum y value.
void setXMaximum(double x) SIP_HOLDGIL
Set the maximum x value.
void setXMinimum(double x) SIP_HOLDGIL
Set the minimum x value.
void setYMaximum(double y) SIP_HOLDGIL
Set the maximum y value.
Contains information about the context of a rendering operation.
double scaleFactor() const
Returns the scaling factor for the render to convert painter units to physical sizes.
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
static QgsRenderContext fromMapSettings(const QgsMapSettings &mapSettings)
create initialized QgsRenderContext instance from given QgsMapSettings
Represents a vector layer which manages a vector based data sets.
bool isSpatial() const FINAL
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeome...
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Queries the layer for features specified in request.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
QgsFeatureRenderer * renderer()
Returns the feature renderer used for rendering the features in the layer in 2D map views.
static GeometryType geometryType(Type type) SIP_HOLDGIL
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
QList< QgsFeature > QgsFeatureList
QList< QgsQuickFeatureLayerPair > QgsQuickFeatureLayerPairs