QgsGeometrySnapper class

QgsGeometrySnapper allows a geometry to be snapped to the geometries within a different reference layer.

Vertices in the geometries will be modified to match the reference layer features within a specified snap tolerance.

Public types

enum SnapMode { PreferNodes = 0, PreferClosest, PreferNodesNoExtraVertices, PreferClosestNoExtraVertices, EndPointPreferNodes, EndPointPreferClosest, EndPointToEndPoint }
Snapping modes.

Public static functions

static auto snapGeometry(const QgsGeometry& geometry, double snapTolerance, const QList<QgsGeometry>& referenceGeometries, SnapMode mode = PreferNodes) -> QgsGeometry
Snaps a single geometry against a list of reference geometries.

Constructors, destructors, conversion operators

QgsGeometrySnapper(QgsFeatureSource* referenceSource)
Constructor for QgsGeometrySnapper.

Public functions

auto snapFeatures(const QgsFeatureList& features, double snapTolerance, SnapMode mode = PreferNodes) -> QgsFeatureList
Snaps a set of features to the reference layer and returns the result.
auto snapGeometry(const QgsGeometry& geometry, double snapTolerance, SnapMode mode = PreferNodes) const -> QgsGeometry
Snaps a geometry to the reference layer and returns the result.

Signals

void featureSnapped()
Emitted each time a feature has been processed when calling snapFeatures()

Enum documentation

enum QgsGeometrySnapper::SnapMode

Snapping modes.

Enumerators
PreferNodes

Prefer to snap to nodes, even when a segment may be closer than a node. New nodes will be inserted to make geometries follow each other exactly when inside allowable tolerance.

PreferClosest

Snap to closest point, regardless of it is a node or a segment. New nodes will be inserted to make geometries follow each other exactly when inside allowable tolerance.

PreferNodesNoExtraVertices

Prefer to snap to nodes, even when a segment may be closer than a node. No new nodes will be inserted.

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 be modified), prefer to snap to nodes.

EndPointPreferClosest

Only snap start/end points of lines (point features will also be snapped, polygon features will not be modified), snap to closest point.

EndPointToEndPoint

Only snap the start/end points of lines to other start/end points of lines.

Function documentation

QgsGeometrySnapper::QgsGeometrySnapper(QgsFeatureSource* referenceSource)

Constructor for QgsGeometrySnapper.

A reference feature source which contains geometries to snap to must be set. It is assumed that all geometries snapped using this object will have the same CRS as the reference source (ie, no reprojection is performed).

QgsFeatureList QgsGeometrySnapper::snapFeatures(const QgsFeatureList& features, double snapTolerance, SnapMode mode = PreferNodes)

Snaps a set of features to the reference layer and returns the result.

This operation is multithreaded for performance. The featureSnapped() signal will be emitted each time a feature is processed. The snap tolerance is specified in the layer units for the reference layer.

QgsGeometry QgsGeometrySnapper::snapGeometry(const QgsGeometry& geometry, double snapTolerance, SnapMode mode = PreferNodes) const

Snaps a geometry to the reference layer and returns the result.

The geometry must be in the same CRS as the reference layer, and must have the same type as the reference layer geometry. The snap tolerance is specified in the layer units for the reference layer.