40 if ( mapSettings == mMapSettings )
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 )
227 if ( filter && !renderer->
willRenderFeature( const_cast<QgsFeature &>( feature ), context ) )
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;
void featuresLimitChanged()
Maximum number of features returned from the QgsQuickIdentifyKit::identify()
void setSearchRadiusMm(double searchRadiusMm)
Search radius for the identify functions.
Wrapper for iterator of features from vector data provider or vector layer.
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.
Base class for all map layer types.
int featuresLimit() const
Maximum number of features returned from the QgsQuickIdentifyKit::identify()
Depends on scale if feature will be rendered (rule based )
OperationResult transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection direction=QgsCoordinateTransform::ForwardTransform, bool transformZ=false) SIP_THROW(QgsCsException)
Transforms this geometry as described by the coordinate transform ct.
void setFeaturesLimit(int limit)
Maximum number of features returned from the QgsQuickIdentifyKit::identify()
void setXMaximum(double x)
Set the maximum x value.
Use exact geometry intersection (slower) instead of bounding boxes.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
Features may be filtered, i.e. some features may not be rendered (categorized, rule based ...
QList< QgsFeature > QgsFeatureList
A class to represent a 2D point.
QgsMapSettings mapSettings() const
Clone map settings.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
double searchRadiusMm() const
Search radius for the identify functions.
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.
A geometry is the spatial representation of a feature.
QList< QgsMapLayer * > layers() const
Gets list of layers for map rendering The layers are stored in the reverse order of how they are rend...
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
The QgsQuickMapSettings class encapsulates QgsMapSettings class to offer settings of configuration of...
bool isSpatial() const FINAL
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeome...
void setMapSettings(QgsQuickMapSettings *mapSettings)
Map settings.
The QgsMapSettings class contains configuration for rendering of the map.
QgsCoordinateTransform layerTransform(const QgsMapLayer *layer) const
Returns the coordinate transform from layer's CRS to destination CRS.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
void searchRadiusMmChanged()
Search radius for the identify functions.
double scale() const
Returns the calculated map scale.
void setYMinimum(double y)
Set the minimum y value.
static GeometryType geometryType(Type type)
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QgsFeatureRequest & setFilterRect(const QgsRectangle &rectangle)
Sets the rectangle from which features will be taken.
QgsFeatureRenderer * renderer()
Returns renderer.
double mapUnitsPerPixel() const
Returns current map units per pixel.
const QgsMapToPixel & mapToPixel() const
QgsQuickMapSettings * mapSettings() const
Map settings.
QgsExpressionContext & expressionContext()
Gets the expression context.
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Contains information about the context of a rendering operation.
const QgsMapToPixel & mapToPixel() const
QgsFeature feature
Feature that belongs to layer.
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)
Must be called when a new render cycle is started.
void setYMaximum(double y)
Set the maximum y value.
static QgsRenderContext fromMapSettings(const QgsMapSettings &mapSettings)
create initialized QgsRenderContext instance from given QgsMapSettings
Q_INVOKABLE QgsQuickFeatureLayerPair identifyOne(const QPointF &point, QgsVectorLayer *layer=nullptr)
Gets the closest feature to the point within the search radius.
virtual void stopRender(QgsRenderContext &context)
Must be called when a render cycle has finished, to allow the renderer to clean up.
QgsVectorLayer layer
Vector layer to which the feature belongs.
QgsFeatureRequest & setLimit(long limit)
Set the maximum number of features to request.
void mapSettingsChanged()
Map settings.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Query the layer for features specified in request.
Q_INVOKABLE QgsQuickFeatureLayerPairs identify(const QPointF &point, QgsVectorLayer *layer=nullptr)
Gets all features in the search radius.
QList< QgsQuickFeatureLayerPair > QgsQuickFeatureLayerPairs
virtual bool willRenderFeature(const QgsFeature &feature, QgsRenderContext &context) const
Returns whether the renderer will render a feature or not.
Custom exception class for Coordinate Reference System related exceptions.
Pair of QgsFeature and QgsVectorLayer.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
bool nextFeature(QgsFeature &f)
QgsPointXY mapToLayerCoordinates(const QgsMapLayer *layer, QgsPointXY point) const
transform point coordinates from output CRS to layer's CRS
double scaleFactor() const
Returns the scaling factor for the render to convert painter units to physical sizes.
Represents a vector layer which manages a vector based data sets.
QgsQuickIdentifyKit(QObject *parent=nullptr)
Constructor of new identify kit.
If the layer is identifiable using the identify map tool and as a WMS layer.
QgsPointXY toMapCoordinates(int x, int y) const
Transform device coordinates to map (world) coordinates.
virtual QgsFeatureRenderer::Capabilities capabilities()
Returns details about internals of this renderer.
static QgsGeometry fromPointXY(const QgsPointXY &point)
Creates a new geometry from a QgsPointXY object.
void setXMinimum(double x)
Set the minimum x value.
QgsFeatureRequest & setFlags(QgsFeatureRequest::Flags flags)
Sets flags that affect how features will be fetched.