17#ifndef QGS_GEOMETRY_SNAPPER_H
18#define QGS_GEOMETRY_SNAPPER_H
22#include "qgis_analysis.h"
73 QgsGeometry snapGeometry(
const QgsGeometry &geometry,
double snapTolerance, SnapMode mode = PreferNodes )
const;
85 static QgsGeometry snapGeometry(
const QgsGeometry &geometry,
double snapTolerance,
const QList<QgsGeometry> &referenceGeometries, SnapMode mode = PreferNodes );
93 struct ProcessFeatureWrapper
99 : instance( _instance )
100 , snapTolerance( snapTolerance )
103 void operator()(
QgsFeature &feature ) { instance->processFeature( feature, snapTolerance, mode ); }
113 QgsFeatureSource *mReferenceSource =
nullptr;
114 QHash<QgsFeatureId, QgsGeometry> mCachedReferenceGeometries;
116 QgsSpatialIndex mIndex;
117 mutable QMutex mIndexMutex;
118 mutable QMutex mReferenceLayerMutex;
120 void processFeature( QgsFeature &feature,
double snapTolerance, SnapMode mode );
122 static int polyLineSize(
const QgsAbstractGeometry *geom,
int iPart,
int iRing );
163 bool mFirstFeature =
true;
164 double mSnapTolerance = 0;
178 CoordIdx(
const QgsAbstractGeometry *_geom, QgsVertexId _vidx )
182 QgsPoint point()
const {
return geom->vertexAt( vidx ); }
184 const QgsAbstractGeometry *geom =
nullptr;
198 virtual ~SnapItem() =
default;
200 virtual QgsPoint getSnapPoint(
const QgsPoint &p )
const = 0;
203 explicit SnapItem( SnapType _type )
207 class PointSnapItem :
public QgsSnapIndex::SnapItem
210 explicit PointSnapItem(
const CoordIdx *_idx,
bool isEndPoint );
211 QgsPoint getSnapPoint(
const QgsPoint & )
const override;
212 const CoordIdx *idx =
nullptr;
215 class SegmentSnapItem :
public QgsSnapIndex::SnapItem
218 SegmentSnapItem(
const CoordIdx *_idxFrom,
const CoordIdx *_idxTo );
219 QgsPoint getSnapPoint(
const QgsPoint &p )
const override;
220 bool getIntersection(
const QgsPoint &p1,
const QgsPoint &p2, QgsPoint &inter )
const;
221 bool getProjection(
const QgsPoint &p, QgsPoint &pProj )
const;
222 bool withinSquaredDistance(
const QgsPoint &p,
const double squaredDistance );
223 const CoordIdx *idxFrom =
nullptr;
224 const CoordIdx *idxTo =
nullptr;
230 QgsSnapIndex(
const QgsSnapIndex &rh ) =
delete;
231 QgsSnapIndex &operator=(
const QgsSnapIndex &rh ) =
delete;
233 void addGeometry(
const QgsAbstractGeometry *geom );
234 QgsPoint getClosestSnapToPoint(
const QgsPoint &startPoint,
const QgsPoint &midPoint );
235 SnapItem *getSnapItem(
const QgsPoint &pos,
const double tolerance, PointSnapItem **pSnapPoint =
nullptr, SegmentSnapItem **pSnapSegment =
nullptr,
bool endPointOnly =
false )
const;
238 QList<CoordIdx *> mCoordIdxs;
239 QList<SnapItem *> mSnapItems;
241 void addPoint(
const CoordIdx *idx,
bool isEndPoint );
242 void addSegment(
const CoordIdx *idxFrom,
const CoordIdx *idxTo );
244 GEOSSTRtree *mSTRTree =
nullptr;
245 std::vector<geos::unique_ptr> mSTRTreeItems;
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...
QgsGeometrySnapper(QgsFeatureSource *referenceSource)
Constructor for QgsGeometrySnapper.
A geometry is the spatial representation of a feature.
QgsInternalGeometrySnapper(double snapTolerance, QgsGeometrySnapper::SnapMode mode=QgsGeometrySnapper::PreferNodes)
Constructor for QgsInternalGeometrySnapper.
QgsGeometry snapFeature(const QgsFeature &feature)
Snaps a single feature's geometry against all feature geometries already processed by calls to snapFe...
QgsGeometryMap snappedGeometries() const
Returns a QgsGeometryMap of all feature geometries snapped by this object.
A spatial index for QgsFeature objects.
Represents a vector layer which manages a vector based dataset.
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
QList< QgsFeature > QgsFeatureList