17#ifndef QGS_GEOMETRY_SNAPPER_H
18#define QGS_GEOMETRY_SNAPPER_H
25#include "qgis_analysis.h"
71 QgsGeometry snapGeometry(
const QgsGeometry &geometry,
double snapTolerance, SnapMode mode = PreferNodes )
const;
83 static QgsGeometry snapGeometry(
const QgsGeometry &geometry,
double snapTolerance,
const QList<QgsGeometry> &referenceGeometries, SnapMode mode = PreferNodes );
91 struct ProcessFeatureWrapper
97 : instance( _instance )
98 , snapTolerance( snapTolerance )
101 void operator()(
QgsFeature &feature ) { instance->processFeature( feature, snapTolerance, mode ); }
104 enum PointFlag { SnappedToRefNode, SnappedToRefSegment, Unsnapped };
107 QHash<QgsFeatureId, QgsGeometry> mCachedReferenceGeometries;
110 mutable QMutex mIndexMutex;
111 mutable QMutex mReferenceLayerMutex;
113 void processFeature(
QgsFeature &feature,
double snapTolerance, SnapMode mode );
158 bool mFirstFeature =
true;
159 double mSnapTolerance = 0;
184 enum SnapType { SnapPoint, SnapEndPoint, SnapSegment };
189 virtual ~SnapItem() =
default;
194 explicit SnapItem( SnapType _type ) : type( _type ) {}
197 class PointSnapItem :
public QgsSnapIndex::SnapItem
200 explicit PointSnapItem(
const CoordIdx *_idx,
bool isEndPoint );
202 const CoordIdx *idx =
nullptr;
205 class SegmentSnapItem :
public QgsSnapIndex::SnapItem
208 SegmentSnapItem(
const CoordIdx *_idxFrom,
const CoordIdx *_idxTo );
212 bool withinSquaredDistance(
const QgsPoint &p,
const double squaredDistance );
213 const CoordIdx *idxFrom =
nullptr;
214 const CoordIdx *idxTo =
nullptr;
220 QgsSnapIndex(
const QgsSnapIndex &rh ) =
delete;
221 QgsSnapIndex &operator=(
const QgsSnapIndex &rh ) =
delete;
225 SnapItem *getSnapItem(
const QgsPoint &pos,
const double tolerance, PointSnapItem **pSnapPoint =
nullptr, SegmentSnapItem **pSnapSegment =
nullptr,
bool endPointOnly =
false )
const;
228 QList<CoordIdx *> mCoordIdxs;
229 QList<SnapItem *> mSnapItems;
231 void addPoint(
const CoordIdx *idx,
bool isEndPoint );
232 void addSegment(
const CoordIdx *idxFrom,
const CoordIdx *idxTo );
234 GEOSSTRtree *mSTRTree =
nullptr;
235 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...
QgsGeometrySnapper allows a geometry to be snapped to the geometries within a different reference lay...
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.
QgsInternalGeometrySnapper 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 data sets.
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
QList< QgsFeature > QgsFeatureList
Utility class for identifying a unique vertex within a geometry.