17 #ifndef QGS_GEOMETRY_SNAPPER_H 18 #define QGS_GEOMETRY_SNAPPER_H 22 #include <QStringList> 27 #include "qgis_analysis.h" 81 static QgsGeometry snapGeometry(
const QgsGeometry &geometry,
double snapTolerance,
const QList<QgsGeometry> &referenceGeometries,
SnapMode mode = PreferNodes );
86 void featureSnapped();
89 struct ProcessFeatureWrapper
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;
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 QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
QgsGeometryMap snappedGeometries() const
Returns a QgsGeometryMap of all feature geometries snapped by this object.
QList< QgsFeature > QgsFeatureList
Only snap the start/end points of lines to other start/end points of lines.
A geometry is the spatial representation of a feature.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QgsPoint vertexAt(QgsVertexId) const override
Returns the point corresponding to a specified vertex id.
Utility class for identifying a unique vertex within a geometry.
Only snap start/end points of lines (point features will also be snapped, polygon features will not b...
QgsGeometrySnapper allows a geometry to be snapped to the geometries within a different reference lay...
Abstract base class for all geometries.
Point geometry type, with support for z-dimension and m-values.
Prefer to snap to nodes, even when a segment may be closer than a node. New nodes will be inserted to...
A spatial index for QgsFeature objects.
Snap to closest point, regardless of it is a node or a segment. New nodes will be inserted to make ge...
An interface for objects which provide features via a getFeatures method.
Prefer to snap to nodes, even when a segment may be closer than a node. No new nodes will be inserted...
Only snap start/end points of lines (point features will also be snapped, polygon features will not b...
Represents a vector layer which manages a vector based data sets.
Snap to closest point, regardless of it is a node or a segment. No new nodes will be inserted...
QgsInternalGeometrySnapper allows a set of geometries to be snapped to each other.