Class: QgsGeometrySnapper

class qgis.analysis.QgsGeometrySnapper(referenceSource: QgsFeatureSource)

Bases: PyQt5.QtCore.QObject

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).

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.

New in version 3.0:

Methods

childEvent

connectNotify

customEvent

disconnectNotify

isSignalConnected

receivers

sender

senderSignalIndex

snapFeatures

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

snapGeometry

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

timerEvent

Signals

featureSnapped

Emitted each time a feature has been processed when calling snapFeatures() [signal]

Attributes

EndPointPreferClosest

EndPointPreferNodes

EndPointToEndPoint

PreferClosest

PreferClosestNoExtraVertices

PreferNodes

PreferNodesNoExtraVertices

EndPointPreferClosest = 5
EndPointPreferNodes = 4
EndPointToEndPoint = 6
PreferClosest = 1
PreferClosestNoExtraVertices = 3
PreferNodes = 0
PreferNodesNoExtraVertices = 2
class SnapMode

Bases: int

childEvent(self, QChildEvent)
connectNotify(self, QMetaMethod)
customEvent(self, QEvent)
disconnectNotify(self, QMetaMethod)
featureSnapped

Emitted each time a feature has been processed when calling snapFeatures() [signal]

isSignalConnected(self, QMetaMethod) bool
receivers(self, PYQT_SIGNAL) int
sender(self) QObject
senderSignalIndex(self) int
snapFeatures(self, features: Iterable[QgsFeature], snapTolerance: float, mode: QgsGeometrySnapper.SnapMode = QgsGeometrySnapper.PreferNodes) List[QgsFeature]

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.

Parameters
  • features (Iterable[QgsFeature]) –

  • snapTolerance (float) –

  • mode (QgsGeometrySnapper.SnapMode = QgsGeometrySnapper.PreferNodes) –

Return type

List[QgsFeature]

snapGeometry(self, geometry: QgsGeometry, snapTolerance: float, mode: QgsGeometrySnapper.SnapMode = QgsGeometrySnapper.PreferNodes) QgsGeometry

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.

snapGeometry(geometry: QgsGeometry, snapTolerance: float, referenceGeometries: Iterable[QgsGeometry], mode: QgsGeometrySnapper.SnapMode = QgsGeometrySnapper.PreferNodes) -> QgsGeometry Snaps a single geometry against a list of reference geometries.

Parameters
  • geometry (QgsGeometry) –

  • snapTolerance (float) –

  • mode (QgsGeometrySnapper.SnapMode = QgsGeometrySnapper.PreferNodes) –

Return type

QgsGeometry

timerEvent(self, QTimerEvent)