17#ifndef QGS_GEOMETRY_SNAPPER_H
18#define QGS_GEOMETRY_SNAPPER_H
25#include "qgis_analysis.h"
72 QgsGeometry snapGeometry(
const QgsGeometry &geometry,
double snapTolerance, SnapMode mode = PreferNodes )
const;
84 static QgsGeometry snapGeometry(
const QgsGeometry &geometry,
double snapTolerance,
const QList<QgsGeometry> &referenceGeometries, SnapMode mode = PreferNodes );
92 struct ProcessFeatureWrapper
98 : instance( _instance )
99 , snapTolerance( snapTolerance )
102 void operator()(
QgsFeature &feature ) { instance->processFeature( feature, snapTolerance, mode ); }
113 QHash<QgsFeatureId, QgsGeometry> mCachedReferenceGeometries;
116 mutable QMutex mIndexMutex;
117 mutable QMutex mReferenceLayerMutex;
119 void processFeature(
QgsFeature &feature,
double snapTolerance, SnapMode mode );
162 bool mFirstFeature =
true;
163 double mSnapTolerance = 0;
197 virtual ~SnapItem() =
default;
202 explicit SnapItem( SnapType _type )
206 class PointSnapItem :
public QgsSnapIndex::SnapItem
209 explicit PointSnapItem(
const CoordIdx *_idx,
bool isEndPoint );
211 const CoordIdx *idx =
nullptr;
214 class SegmentSnapItem :
public QgsSnapIndex::SnapItem
217 SegmentSnapItem(
const CoordIdx *_idxFrom,
const CoordIdx *_idxTo );
221 bool withinSquaredDistance(
const QgsPoint &p,
const double squaredDistance );
222 const CoordIdx *idxFrom =
nullptr;
223 const CoordIdx *idxTo =
nullptr;
229 QgsSnapIndex(
const QgsSnapIndex &rh ) =
delete;
230 QgsSnapIndex &operator=(
const QgsSnapIndex &rh ) =
delete;
234 SnapItem *getSnapItem(
const QgsPoint &pos,
const double tolerance, PointSnapItem **pSnapPoint =
nullptr, SegmentSnapItem **pSnapSegment =
nullptr,
bool endPointOnly =
false )
const;
237 QList<CoordIdx *> mCoordIdxs;
238 QList<SnapItem *> mSnapItems;
240 void addPoint(
const CoordIdx *idx,
bool isEndPoint );
241 void addSegment(
const CoordIdx *idxFrom,
const CoordIdx *idxTo );
243 GEOSSTRtree *mSTRTree =
nullptr;
244 std::vector<geos::unique_ptr> mSTRTreeItems;
Abstract base class for all geometries.
An interface for objects which provide features via a getFeatures method.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Allows a geometry to be snapped to the geometries within a different reference layer.
void featureSnapped()
Emitted each time a feature has been processed when calling snapFeatures()
@ EndPointPreferClosest
Only snap start/end points of lines (point features will also be snapped, polygon features will not b...
@ PreferClosestNoExtraVertices
Snap to closest point, regardless of it is a node or a segment. No new nodes will be inserted.
@ EndPointPreferNodes
Only snap start/end points of lines (point features will also be snapped, polygon features will not b...
@ PreferNodes
Prefer to snap to nodes, even when a segment may be closer than a node. New nodes will be inserted to...
@ PreferClosest
Snap to closest point, regardless of it is a node or a segment. New nodes will be inserted to make ge...
@ EndPointToEndPoint
Only snap the start/end points of lines to other start/end points of lines.
@ PreferNodesNoExtraVertices
Prefer to snap to nodes, even when a segment may be closer than a node. No new nodes will be inserted...
A geometry is the spatial representation of a feature.
Allows a set of geometries to be snapped to each other.
QgsGeometryMap snappedGeometries() const
Returns a QgsGeometryMap of all feature geometries snapped by this object.
Point geometry type, with support for z-dimension and m-values.
QgsPoint vertexAt(QgsVertexId) const override
Returns the point corresponding to a specified vertex id.
A spatial index for QgsFeature objects.
Represents a vector layer which manages a vector based dataset.
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
QList< QgsFeature > QgsFeatureList
Utility class for identifying a unique vertex within a geometry.