17 #ifndef QGS_GEOMETRY_SNAPPER_H
18 #define QGS_GEOMETRY_SNAPPER_H
25 #include "qgis_analysis.h"
29 #include <QStringList>
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 ); }
105 enum PointFlag { SnappedToRefNode, SnappedToRefSegment, Unsnapped };
108 QHash<QgsFeatureId, QgsGeometry> mCachedReferenceGeometries;
111 mutable QMutex mIndexMutex;
112 mutable QMutex mReferenceLayerMutex;
114 void processFeature(
QgsFeature &feature,
double snapTolerance, SnapMode mode );
160 bool mFirstFeature =
true;
161 double mSnapTolerance = 0;
186 enum SnapType { SnapPoint, SnapEndPoint, SnapSegment };
191 virtual ~SnapItem() =
default;
196 explicit SnapItem( SnapType _type ) : type( _type ) {}
199 class PointSnapItem :
public QgsSnapIndex::SnapItem
202 explicit PointSnapItem(
const CoordIdx *_idx,
bool isEndPoint );
204 const CoordIdx *idx =
nullptr;
207 class SegmentSnapItem :
public QgsSnapIndex::SnapItem
210 SegmentSnapItem(
const CoordIdx *_idxFrom,
const CoordIdx *_idxTo );
214 const CoordIdx *idxFrom =
nullptr;
215 const CoordIdx *idxTo =
nullptr;
218 QgsSnapIndex(
const QgsPoint &origin,
double cellSize );
221 QgsSnapIndex(
const QgsSnapIndex &rh ) =
delete;
222 QgsSnapIndex &operator=(
const QgsSnapIndex &rh ) =
delete;
226 SnapItem *getSnapItem(
const QgsPoint &pos,
double tol, PointSnapItem **pSnapPoint =
nullptr, SegmentSnapItem **pSnapSegment =
nullptr,
bool endPointOnly =
false )
const;
229 typedef QList<SnapItem *> Cell;
230 typedef QPair<QgsPoint, QgsPoint> Segment;
235 QList<CoordIdx *> mCoordIdxs;
236 QList<SnapItem *> mSnapItems;
238 void addPoint(
const CoordIdx *idx,
bool isEndPoint );
239 void addSegment(
const CoordIdx *idxFrom,
const CoordIdx *idxTo );
241 GEOSSTRtree *mSTRTree =
nullptr;
242 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.