Subgroup: Snapping
Class: QgsSnappingUtils¶
-
class
qgis.core.
QgsSnappingUtils
¶ Bases:
PyQt5.QtCore.QObject
This class has all the configuration of snapping and can return answers to snapping queries. Internally, it keeps a cache of QgsPointLocator instances for multiple layers.
Currently it supports the following queries: - snapToMap() - has multiple modes of operation - snapToCurrentLayer() For more complex queries it is possible to use locatorForLayer() method that returns point locator instance with layer’s indexed data.
Indexing strategy determines how fast the queries will be and how much memory will be used.
When working with map canvas, it may be useful to use derived class QgsMapCanvasSnappingUtils which keeps the configuration in sync with map canvas (e.g. current view, active layer).
New in version 2.8: Methods
blockSignals
childEvent
children
clearAllLocators
Deletes all existing locators (e.g. config
The snapping configuration controls the behavior of this object connectNotify
currentLayer
The current layer used if mode is SnapCurrentLayer customEvent
deleteLater
disconnect
disconnectNotify
dump
Get extra information about the instance dumpObjectInfo
dumpObjectTree
dynamicPropertyNames
event
eventFilter
findChild
findChild(self, Tuple, name: str = ‘’, options: Union[Qt.FindChildOptions, Qt.FindChildOption] = Qt.FindChildrenRecursively) -> QObject findChildren
findChildren(self, Tuple, name: str = ‘’, options: Union[Qt.FindChildOptions, Qt.FindChildOption] = Qt.FindChildrenRecursively) -> List[QObject] indexingStrategy
Find out which strategy is used for indexing - by default hybrid indexing is used inherits
installEventFilter
isSignalConnected
isWidgetType
isWindowType
killTimer
layers
Query layers used for snapping locatorForLayer
Get a point locator for the given layer. mapSettings
metaObject
moveToThread
objectName
parent
prepareIndexProgress
Called when finished indexing a layer. prepareIndexStarting
Called when starting to index - can be overridden and e.g. property
pyqtConfigure
Each keyword argument is either the name of a Qt property or a Qt signal. receivers
removeEventFilter
sender
senderSignalIndex
setConfig
The snapping configuration controls the behavior of this object setCurrentLayer
Set current layer so that if mode is SnapCurrentLayer we know which layer to use setIndexingStrategy
Set a strategy for indexing geometry data - determines how fast and memory consuming the data structures will be setMapSettings
Assign current map settings to the utils - used for conversion between screen coords to map coords setObjectName
setParent
setProperty
signalsBlocked
snapToCurrentLayer
Snap to current layer snapToMap
Snap to map according to the current configuration. startTimer
thread
timerEvent
toggleEnabled
Toggles the state of snapping tr
Attributes
IndexAlwaysFull
IndexExtent
IndexHybrid
IndexNeverFull
configChanged
Emitted when the snapping settings object changes. destroyed
destroyed(self, QObject = None) [signal] objectNameChanged
objectNameChanged(self, str) [signal] staticMetaObject
-
IndexAlwaysFull
= 0¶
-
IndexExtent
= 3¶
-
IndexHybrid
= 2¶
-
IndexNeverFull
= 1¶
-
class
IndexingStrategy
¶ Bases:
int
-
class
LayerConfig
(l: QgsVectorLayer, t: Union[QgsPointLocator.Types, QgsPointLocator.Type], tol: float, u: QgsTolerance.UnitType)¶ Bases:
sip.wrapper
Create a new configuration for a snapping layer.
```py snapper = QgsMapCanvasSnappingUtils(mapCanvas)
snapping_layer1 = QgsSnappingUtils.LayerConfig(layer1, QgsPointLocator.Vertex, 10, QgsTolerance.Pixels) snapping_layer2 = QgsSnappingUtils.LayerConfig(layer2, QgsPointLocator.Vertex and QgsPointLocator.Edge, 10, QgsTolerance.Pixels)
snapper.setLayers([snapping_layer1, snapping_layer2]) ```
Parameters: - l – The vector layer for which this configuration is
- t – Which parts of the geometry should be snappable
- tol – The tolerance radius in which the snapping will trigger
- u – The unit in which the tolerance is specified
QgsSnappingUtils.LayerConfig(QgsSnappingUtils.LayerConfig)
-
layer
¶
-
tolerance
¶
-
type
¶
-
unit
¶
-
childEvent
()¶
-
clearAllLocators
(self)¶ Deletes all existing locators (e.g. when destination CRS has changed and we need to reindex)
-
config
(self) → QgsSnappingConfig¶ The snapping configuration controls the behavior of this object
-
configChanged
¶ Emitted when the snapping settings object changes. [signal]
-
connectNotify
()¶
-
currentLayer
(self) → QgsVectorLayer¶ The current layer used if mode is SnapCurrentLayer
-
customEvent
()¶
-
disconnectNotify
()¶
-
dump
(self) → str¶ Get extra information about the instance
New in version 2.14.
-
indexingStrategy
(self) → QgsSnappingUtils.IndexingStrategy¶ Find out which strategy is used for indexing - by default hybrid indexing is used
-
isSignalConnected
()¶
-
layers
(self) → object¶ Query layers used for snapping
-
locatorForLayer
(self, vl: QgsVectorLayer) → QgsPointLocator¶ Get a point locator for the given layer. If such locator does not exist, it will be created
-
mapSettings
(self) → QgsMapSettings¶
-
prepareIndexProgress
(self, index: int)¶ Called when finished indexing a layer. When index == count the indexing is complete
-
prepareIndexStarting
(self, count: int)¶ Called when starting to index - can be overridden and e.g. progress dialog can be provided
-
receivers
()¶
-
sender
()¶
-
senderSignalIndex
()¶
-
setConfig
(self, snappingConfig: QgsSnappingConfig)¶ The snapping configuration controls the behavior of this object
-
setCurrentLayer
(self, layer: QgsVectorLayer)¶ Set current layer so that if mode is SnapCurrentLayer we know which layer to use
-
setIndexingStrategy
(self, strategy: QgsSnappingUtils.IndexingStrategy)¶ Set a strategy for indexing geometry data - determines how fast and memory consuming the data structures will be
-
setMapSettings
(self, settings: QgsMapSettings)¶ Assign current map settings to the utils - used for conversion between screen coords to map coords
-
snapToCurrentLayer
(self, point: QPoint, type: Union[QgsPointLocator.Types, QgsPointLocator.Type], filter: QgsPointLocator.MatchFilter = None) → QgsPointLocator.Match¶ Snap to current layer
-
snapToMap
(self, point: QPoint, filter: QgsPointLocator.MatchFilter = None) → QgsPointLocator.Match¶ Snap to map according to the current configuration. Optional filter allows discarding unwanted matches.
snapToMap(self, pointMap: QgsPointXY, filter: QgsPointLocator.MatchFilter = None) -> QgsPointLocator.Match
-
timerEvent
()¶
-
toggleEnabled
(self)¶ Toggles the state of snapping
New in version 3.0.
-