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 );
164 bool mFirstFeature =
true;
165 double mSnapTolerance = 0;
179 CoordIdx(
const QgsAbstractGeometry *_geom, QgsVertexId _vidx )
183 QgsPoint point()
const {
return geom->vertexAt( vidx ); }
185 const QgsAbstractGeometry *geom =
nullptr;
199 virtual ~SnapItem() =
default;
201 virtual QgsPoint getSnapPoint(
const QgsPoint &p )
const = 0;
204 explicit SnapItem( SnapType _type )
208 class PointSnapItem :
public QgsSnapIndex::SnapItem
211 explicit PointSnapItem(
const CoordIdx *_idx,
bool isEndPoint );
212 QgsPoint getSnapPoint(
const QgsPoint & )
const override;
213 const CoordIdx *idx =
nullptr;
216 class SegmentSnapItem :
public QgsSnapIndex::SnapItem
219 SegmentSnapItem(
const CoordIdx *_idxFrom,
const CoordIdx *_idxTo );
220 QgsPoint getSnapPoint(
const QgsPoint &p )
const override;
221 bool getIntersection(
const QgsPoint &p1,
const QgsPoint &p2, QgsPoint &inter )
const;
222 bool getProjection(
const QgsPoint &p, QgsPoint &pProj )
const;
223 bool withinSquaredDistance(
const QgsPoint &p,
const double squaredDistance );
224 const CoordIdx *idxFrom =
nullptr;
225 const CoordIdx *idxTo =
nullptr;
231 QgsSnapIndex(
const QgsSnapIndex &rh ) =
delete;
232 QgsSnapIndex &operator=(
const QgsSnapIndex &rh ) =
delete;
234 void addGeometry(
const QgsAbstractGeometry *geom );
235 QgsPoint getClosestSnapToPoint(
const QgsPoint &startPoint,
const QgsPoint &midPoint );
236 SnapItem *getSnapItem(
const QgsPoint &pos,
const double tolerance, PointSnapItem **pSnapPoint =
nullptr, SegmentSnapItem **pSnapSegment =
nullptr,
bool endPointOnly =
false )
const;
239 QList<CoordIdx *> mCoordIdxs;
240 QList<SnapItem *> mSnapItems;
242 void addPoint(
const CoordIdx *idx,
bool isEndPoint );
243 void addSegment(
const CoordIdx *idxFrom,
const CoordIdx *idxTo );
245 GEOSSTRtree *mSTRTree =
nullptr;
246 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