17 #ifndef QGS_GEOMETRY_SNAPPER_H
18 #define QGS_GEOMETRY_SNAPPER_H
22 #include <QStringList>
27 #include "qgis_analysis.h"
69 QgsGeometry snapGeometry(
const QgsGeometry &geometry,
double snapTolerance, SnapMode mode = PreferNodes )
const;
81 static QgsGeometry snapGeometry(
const QgsGeometry &geometry,
double snapTolerance,
const QList<QgsGeometry> &referenceGeometries, SnapMode mode = PreferNodes );
86 void featureSnapped();
89 struct ProcessFeatureWrapper
94 explicit ProcessFeatureWrapper(
QgsGeometrySnapper *_instance,
double snapTolerance, SnapMode mode )
95 : instance( _instance )
96 , snapTolerance( snapTolerance )
99 void operator()(
QgsFeature &feature ) { instance->processFeature( feature, snapTolerance, mode ); }
102 enum PointFlag { SnappedToRefNode, SnappedToRefSegment, Unsnapped };
108 mutable QMutex mIndexMutex;
109 mutable QMutex mReferenceLayerMutex;
111 void processFeature(
QgsFeature &feature,
double snapTolerance, SnapMode mode );
157 bool mFirstFeature =
true;
158 double mSnapTolerance = 0;
183 enum SnapType { SnapPoint, SnapEndPoint, SnapSegment };
188 virtual ~SnapItem() =
default;
193 explicit SnapItem( SnapType _type ) : type( _type ) {}
196 class PointSnapItem :
public QgsSnapIndex::SnapItem
199 explicit PointSnapItem(
const CoordIdx *_idx,
bool isEndPoint );
201 const CoordIdx *idx =
nullptr;
204 class SegmentSnapItem :
public QgsSnapIndex::SnapItem
207 SegmentSnapItem(
const CoordIdx *_idxFrom,
const CoordIdx *_idxTo );
211 const CoordIdx *idxFrom =
nullptr;
212 const CoordIdx *idxTo =
nullptr;
215 QgsSnapIndex(
const QgsPoint &origin,
double cellSize );
218 QgsSnapIndex(
const QgsSnapIndex &rh ) =
delete;
219 QgsSnapIndex &operator=(
const QgsSnapIndex &rh ) =
delete;
223 SnapItem *getSnapItem(
const QgsPoint &pos,
double tol, PointSnapItem **pSnapPoint =
nullptr, SegmentSnapItem **pSnapSegment =
nullptr,
bool endPointOnly =
false )
const;
226 typedef QList<SnapItem *> Cell;
227 typedef QPair<QgsPoint, QgsPoint> Segment;
234 const Cell *getCell(
int col )
const;
235 Cell &getCreateCell(
int col );
236 QList<SnapItem *> getSnapItems(
int colStart,
int colEnd )
const;
239 QList<QgsSnapIndex::Cell> mCells;
240 int mColStartIdx = 0;
246 QList<CoordIdx *> mCoordIdxs;
247 QList<GridRow> mGridRows;
250 void addPoint(
const CoordIdx *idx,
bool isEndPoint );
251 void addSegment(
const CoordIdx *idxFrom,
const CoordIdx *idxTo );
252 const Cell *getCell(
int col,
int row )
const;
253 Cell &getCreateCell(
int col,
int row );
261 #endif // QGS_GEOMETRY_SNAPPER_H