16#ifndef QGSPOINTLOCATOR_H
17#define QGSPOINTLOCATOR_H
85 class IStorageManager;
157 MiddleOfSegment = 1 << 4,
158 LineEndpoint = 1 << 5,
159 All = Vertex | Edge | Area | Centroid | MiddleOfSegment
177 bool init(
int maxFeaturesToIndex = -1,
bool relaxed =
false );
180 bool hasIndex()
const;
193 , mVertexIndex( vertexIndex )
197 mEdgePoints[0] = edgePoints[0];
198 mEdgePoints[1] = edgePoints[1];
204 bool isValid()
const {
return mType != Invalid; }
208 bool hasEdge()
const {
return mType == Edge; }
212 bool hasArea()
const {
return mType == Area; }
252 pt1 = mEdgePoints[0];
253 pt2 = mEdgePoints[1];
269 const QgsGeometry geom = mLayer->getGeometry( mFid );
275 snappedPoint = transform.
transform( snappedPoint );
279 QgsDebugError( QStringLiteral(
"transformation to layer coordinate failed" ) );
307 QgsDebugError( QStringLiteral(
"transformation to destination coordinate failed" ) );
318 return mType == other.
mType &&
319 mDist == other.
mDist &&
322 mFid == other.
mFid &&
336 int mVertexIndex = 0;
345 typedef QList<QgsPointLocator::Match>
MatchList;
466 void waitForIndexingFinished();
478 bool rebuildIndex(
int maxFeaturesToIndex = -1 );
483 void onInitTaskFinished();
487 void onAttributeValueChanged(
QgsFeatureId fid,
int idx,
const QVariant &value );
495 bool prepare(
bool relaxed );
498 std::unique_ptr< SpatialIndex::IStorageManager > mStorage;
500 QHash<QgsFeatureId, QgsGeometry *> mGeoms;
501 std::unique_ptr< SpatialIndex::ISpatialIndex > mRTree;
504 bool mIsEmptyLayer =
false;
510 std::unique_ptr< QgsRectangle > mExtent;
512 std::unique_ptr<QgsRenderContext> mContext;
513 std::unique_ptr<QgsFeatureRenderer> mRenderer;
514 std::unique_ptr<QgsVectorLayerFeatureSource> mSource;
515 int mMaxFeaturesToIndex = -1;
516 bool mIsIndexing =
false;
517 bool mIsDestroying =
false;
520 QPointer<QgsPointLocatorInitTask> mInitTask;
529 friend class QgsPointLocatorInitTask;
530 friend class TestQgsPointLocator;
@ Reverse
Reverse/inverse transform (from destination to source)
This class represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
Custom exception class for Coordinate Reference System related exceptions.
Abstract base class for all 2D vector feature renderers.
static QgsPoint closestPoint(const QgsAbstractGeometry &geometry, const QgsPoint &point)
Returns the nearest point on a segment of a geometry for the specified point.
A geometry is the spatial representation of a feature.
QgsPoint vertexAt(int atVertex) const
Returns coordinates of a vertex.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
Qgis::WkbType wkbType() const
Returns type of the geometry as a WKB type (point / linestring / polygon etc.)
Line string geometry type, with support for z-dimension and m-values.
Helper class used when traversing the index with areas - builds a list of matches.
Helper class used when traversing the index looking for centroid - builds a list of matches.
Helper class used when traversing the index looking for edges - builds a list of matches.
Helper class used when traversing the index looking for middle segment - builds a list of matches.
Helper class used when traversing the index looking for centroid - builds a list of matches.
Helper class used when traversing the index looking for edges - builds a list of matches.
Helper class used when traversing the index looking for line endpoints (start or end vertex) - builds...
Helper class used when traversing the index looking for middle segment - builds a list of matches.
Helper class used when traversing the index looking for vertices - builds a list of matches.
Helper class used when traversing the index looking for vertices - builds a list of matches.
The class defines interface for querying point location:
int cachedGeometryCount() const
Returns how many geometries are cached in the index.
QgsVectorLayer * layer() const
Gets associated layer.
class QList< QgsPointLocator::Match > MatchList
bool isIndexing() const
Returns true if the point locator is currently indexing the data.
const QgsRectangle * extent() const
Gets extent of the area point locator covers - if nullptr then it caches the whole layer.
void initFinished(bool ok)
Emitted whenever index has been built and initialization is finished.
Type
The type of a snap result or the filter type for a snap request.
A class to represent a 2D point.
Point geometry type, with support for z-dimension and m-values.
void transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection d=Qgis::TransformDirection::Forward, bool transformZ=false) override
Transforms the geometry using a coordinate transform.
A rectangle specified with double values.
Contains information about the context of a rendering operation.
Partial snapshot of vector layer's state (only the members necessary for access to features)
Represents a vector layer which manages a vector based data sets.
static bool isCurvedType(Qgis::WkbType type)
Returns true if the WKB type is a curved type or can contain curved geometries.
#define SIP_ENUM_BASETYPE(type)
QSet< QgsFeatureId > QgsFeatureIds
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
#define QgsDebugError(str)
Interface that allows rejection of some matches in intersection queries (e.g.
virtual bool acceptMatch(const QgsPointLocator::Match &match)=0
virtual ~MatchFilter()=default
QgsFeatureId featureId() const
The id of the feature to which the snapped geometry belongs.
bool hasCentroid() const
Returns true if the Match is a centroid.
QgsVectorLayer * layer() const
The vector layer where the snap occurred.
QgsPoint interpolatedPoint(const QgsCoordinateReferenceSystem &destinationCrs=QgsCoordinateReferenceSystem()) const
Convenient method to return a point on an edge with linear interpolation of the Z value.
double distance() const
for vertex / edge match units depending on what class returns it (geom.cache: layer units,...
QgsPointXY mMiddleOfSegment
QgsPointXY point() const
for vertex / edge match coords depending on what class returns it (geom.cache: layer coords,...
bool hasEdge() const
Returns true if the Match is an edge.
void edgePoints(QgsPointXY &pt1, QgsPointXY &pt2) const
Only for a valid edge match - obtain endpoints of the edge.
bool hasArea() const
Returns true if the Match is an area.
Match()=default
construct invalid match
Match(QgsPointLocator::Type t, QgsVectorLayer *vl, QgsFeatureId fid, double dist, const QgsPointXY &pt, int vertexIndex=0, QgsPointXY *edgePoints=nullptr)
QgsPointLocator::Type type() const
QgsPointXY mEdgePoints[2]
bool hasLineEndpoint() const
Returns true if the Match is a line endpoint (start or end vertex).
bool hasMiddleSegment() const
Returns true if the Match is the middle of a segment.
int vertexIndex() const
for vertex / edge match (first vertex of the edge)
bool hasVertex() const
Returns true if the Match is a vertex.
bool operator==(const QgsPointLocator::Match &other) const