QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
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 );
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;
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
@ PreferNodes
Prefer to snap to nodes, even when a segment may be closer than a node. New nodes will be inserted to...
@ PreferClosestNoExtraVertices
Snap to closest point, regardless of it is a node or a segment. No new nodes will be inserted.
QgsPoint vertexAt(QgsVertexId) const override
Returns the point corresponding to a specified vertex id.
Point geometry type, with support for z-dimension and m-values.
An interface for objects which provide features via a getFeatures method.
@ PreferClosest
Snap to closest point, regardless of it is a node or a segment. New nodes will be inserted to make ge...
QgsGeometryMap snappedGeometries() const
Returns a QgsGeometryMap of all feature geometries snapped by this object.
@ EndPointToEndPoint
Only snap the start/end points of lines to other start/end points of lines.
QList< QgsFeature > QgsFeatureList
@ EndPointPreferNodes
Only snap start/end points of lines (point features will also be snapped, polygon features will not b...
A spatial index for QgsFeature objects.
Abstract base class for all geometries.
A geometry is the spatial representation of a feature.
Represents a vector layer which manages a vector based data sets.
QgsInternalGeometrySnapper allows a set of geometries to be snapped to each other.
Utility class for identifying a unique vertex within a geometry.
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
void featureSnapped()
Emitted each time a feature has been processed when calling snapFeatures()
QgsGeometrySnapper allows a geometry to be snapped to the geometries within a different reference lay...
@ PreferNodesNoExtraVertices
Prefer to snap to nodes, even when a segment may be closer than a node. No new nodes will be inserted...
@ EndPointPreferClosest
Only snap start/end points of lines (point features will also be snapped, polygon features will not b...