17#ifndef QGS_GEOMETRY_SNAPPER_H
18#define QGS_GEOMETRY_SNAPPER_H
25#include "qgis_analysis.h"
70 QgsGeometry snapGeometry(
const QgsGeometry &geometry,
double snapTolerance, SnapMode mode = PreferNodes )
const;
82 static QgsGeometry snapGeometry(
const QgsGeometry &geometry,
double snapTolerance,
const QList<QgsGeometry> &referenceGeometries, SnapMode mode = PreferNodes );
90 struct ProcessFeatureWrapper
96 : instance( _instance )
97 , snapTolerance( snapTolerance )
100 void operator()(
QgsFeature &feature ) { instance->processFeature( feature, snapTolerance, mode ); }
111 QHash<QgsFeatureId, QgsGeometry> mCachedReferenceGeometries;
114 mutable QMutex mIndexMutex;
115 mutable QMutex mReferenceLayerMutex;
117 void processFeature(
QgsFeature &feature,
double snapTolerance, SnapMode mode );
158 bool mFirstFeature =
true;
159 double mSnapTolerance = 0;
193 virtual ~SnapItem() =
default;
198 explicit SnapItem( SnapType _type )
202 class PointSnapItem :
public QgsSnapIndex::SnapItem
205 explicit PointSnapItem(
const CoordIdx *_idx,
bool isEndPoint );
207 const CoordIdx *idx =
nullptr;
210 class SegmentSnapItem :
public QgsSnapIndex::SnapItem
213 SegmentSnapItem(
const CoordIdx *_idxFrom,
const CoordIdx *_idxTo );
217 bool withinSquaredDistance(
const QgsPoint &p,
const double squaredDistance );
218 const CoordIdx *idxFrom =
nullptr;
219 const CoordIdx *idxTo =
nullptr;
225 QgsSnapIndex(
const QgsSnapIndex &rh ) =
delete;
226 QgsSnapIndex &operator=(
const QgsSnapIndex &rh ) =
delete;
230 SnapItem *getSnapItem(
const QgsPoint &pos,
const double tolerance, PointSnapItem **pSnapPoint =
nullptr, SegmentSnapItem **pSnapSegment =
nullptr,
bool endPointOnly =
false )
const;
233 QList<CoordIdx *> mCoordIdxs;
234 QList<SnapItem *> mSnapItems;
236 void addPoint(
const CoordIdx *idx,
bool isEndPoint );
237 void addSegment(
const CoordIdx *idxFrom,
const CoordIdx *idxTo );
239 GEOSSTRtree *mSTRTree =
nullptr;
240 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.