Class: QgsMapToolCapture

class qgis.gui.QgsMapToolCapture

Bases: QgsMapToolAdvancedDigitizing

QgsMapToolCapture is a base class capable of capturing point, lines and polygons. The tool supports different techniques: straight segments, curves, streaming and shapes Once the the geometry is captured the virtual private handler geometryCaptured is called as well as a more specific handler (pointCaptured, lineCaptured or polygonCaptured)

QgsMapToolCapture(canvas: QgsMapCanvas, cadDockWidget: QgsAdvancedDigitizingDockWidget, mode: QgsMapToolCapture.CaptureMode) constructor

Enums

CaptureTechnique

Bases: enum.IntEnum

Methods

activate

addCurve

Adds a whole curve (e.g. circularstring) to the captured geometry.

addTopologicalPoints

Adds a list of vertices to other features to keep topology up to date, e.g. to neighbouring polygons.

addVertex

Adds a point to the rubber band (in map coordinates) and to the capture list (in layer coordinates)

cadCanvasMoveEvent

param e:

cadCanvasReleaseEvent

param e:

capabilities

Returns flags containing the supported capabilities

captureCurve

Gets the capture curve

childEvent

clean

convenient method to clean members

clearCurve

Clear capture curve.

closePolygon

Close an open polygon

connectNotify

createRubberBand

Creates a rubber band with the color/line width from the QGIS settings.

currentCaptureTechnique

Returns the active capture technique

currentVectorLayer

Returns the current vector layer of the map canvas or 0

customEvent

deactivate

deleteTempRubberBand

Clean a temporary rubberband

digitizingFillColor

Returns fill color for rubber bands (from global settings)

digitizingStrokeColor

Returns stroke color for rubber bands (from global settings)

digitizingStrokeWidth

Returns stroke width for rubber bands (from global settings)

disconnectNotify

fetchLayerPoint

Fetches the original point from the source layer if it has the same CRS as the current layer.

geometryCaptured

isCapturing

Are we currently capturing?

isSignalConnected

keyPressEvent

Intercept key events like Esc or Del to delete the last point

lineCaptured

mapPoint

Creates a QgsPoint with ZM support if necessary (according to the WkbType of the current layer).

mode

The capture mode

nextPoint

Converts a map point to layer coordinates

notifyNotEditableLayer

Display a timed message bar noting the active vector layer is not editable.

notifyNotVectorLayer

Display a timed message bar noting the active layer is not vector.

pointCaptured

points

List of digitized points

pointsZM

List of digitized points

polygonCaptured

receivers

sender

senderSignalIndex

setAdvancedDigitizingAllowed

Sets whether functionality of advanced digitizing dock widget is currently allowed.

setAutoSnapEnabled

Sets whether mouse events (press/move/release) should automatically try to snap mouse position This method is protected because it should be a decision of the map tool and not from elsewhere.

setCircularDigitizingEnabled

Enable the digitizing with curve

setCurrentCaptureTechnique

Sets the current capture if it is supported by the map tool

setPoints

Set the points on which to work

setStreamDigitizingEnabled

Toggles the stream digitizing mode.

setToolName

Sets the tool's name.

size

Number of points digitized

snappingMatches

Returns a list of matches for each point on the captureCurve.

startCapturing

Start capturing

stopCapturing

Stop capturing

supportsTechnique

Returns True if the tool supports the specified capture technique.

takeRubberBand

Returns the rubberBand currently owned by this map tool and transfers ownership to the caller.

timerEvent

toCanvasCoordinates

Transforms a point from map coordinates to screen coordinates.

toLayerCoordinates

Transforms a point from screen coordinates to layer coordinates.

toLayerCoordinatesV2

Transforms a point from map coordinates to layer coordinates.

toMapCoordinates

Transforms a point from screen coordinates to map coordinates.

toMapCoordinatesV2

Transforms a point from layer coordinates to map coordinates (which is different in case reprojection is used).

undo

Removes the last vertex from mRubberBand and mCaptureList.

Attributes

CaptureLine

CaptureNone

CapturePoint

CapturePolygon

NoCapabilities

SupportsCurves

ValidateGeometries

class Capabilities
class Capabilities(Union[QgsMapToolCapture.Capabilities, QgsMapToolCapture.Capability])
class Capabilities(QgsMapToolCapture.Capabilities)

Bases: sip.wrapper

class Capability

Bases: int

CaptureLine = 2
class CaptureMode

Bases: int

CaptureNone = 0
CapturePoint = 1
CapturePolygon = 3
class CaptureTechnique(value)

Bases: enum.IntEnum

Capture technique.

New in version 3.26.

  • StraightSegments: Default capture mode - capture occurs with straight line segments

  • CircularString: Capture in circular strings

  • Streaming: Streaming points digitizing mode (points are automatically added as the mouse cursor moves).

  • Shape: Digitize shapes.

baseClass

alias of Qgis

NoCapabilities = 1
SupportsCurves = 2
ValidateGeometries = 4
activate(self)
addCurve(self, c: QgsCurve) int

Adds a whole curve (e.g. circularstring) to the captured geometry. Curve must be in map CRS

Parameters:

c (QgsCurve) –

Return type:

int

addTopologicalPoints(self, vertices: Iterable[QgsPointXY]) QgsMapToolEdit.TopologicalResult

Adds a list of vertices to other features to keep topology up to date, e.g. to neighbouring polygons. The vertices list specifies a set of topological points to add, in the layer’s coordinate reference system.

Deprecated since version QGIS: 3.12 - will be removed in QGIS 4.0. Use the variant which accepts QgsPoint objects instead of QgsPointXY.

addTopologicalPoints(self, vertices: Iterable[QgsPoint]) -> QgsMapToolEdit.TopologicalResult Adds a list of vertices to other features to keep topology up to date, e.g. to neighbouring polygons. The vertices list specifies a set of topological points to add, in the layer’s coordinate reference system.

New in version 3.10.

addVertex(self, point: QgsPointXY) int

Adds a point to the rubber band (in map coordinates) and to the capture list (in layer coordinates)

Return type:

int

Returns:

0 in case of success, 2 if coordinate transformation failed

addVertex(self, mapPoint: QgsPointXY, match: QgsPointLocator.Match) -> int Variant to supply more information in the case of snapping

Parameters:
  • mapPoint – The vertex to add in map coordinates

  • match – Data about the snapping match. Can be an invalid match, if point not snapped.

  • point (QgsPointXY) –

cadCanvasMoveEvent(self, e: QgsMapMouseEvent)
Parameters:

e (QgsMapMouseEvent) –

cadCanvasReleaseEvent(self, e: QgsMapMouseEvent)
Parameters:

e (QgsMapMouseEvent) –

capabilities(self) QgsMapToolCapture.Capabilities

Returns flags containing the supported capabilities

Return type:

QgsMapToolCapture.Capabilities

captureCurve(self) QgsCompoundCurve

Gets the capture curve

Return type:

QgsCompoundCurve

Returns:

Capture curve

childEvent(self, QChildEvent)
clean(self)

convenient method to clean members

clearCurve(self)

Clear capture curve.

closePolygon(self)

Close an open polygon

connectNotify(self, QMetaMethod)
createRubberBand(self, geometryType: Qgis.GeometryType = Qgis.GeometryType.Line, alternativeBand: bool = False) QgsRubberBand

Creates a rubber band with the color/line width from the QGIS settings. The caller takes ownership of the returned object

Parameters:
  • geometryType

  • alternativeBand – if True, rubber band will be set with more transparency and a dash pattern. default is False.

currentCaptureTechnique(self) Qgis.CaptureTechnique

Returns the active capture technique

New in version 3.32.

Return type:

Qgis.CaptureTechnique

currentVectorLayer(self) QgsVectorLayer

Returns the current vector layer of the map canvas or 0

customEvent(self, QEvent)
deactivate(self)
deleteTempRubberBand(self)

Clean a temporary rubberband

digitizingFillColor() QColor

Returns fill color for rubber bands (from global settings)

digitizingStrokeColor() QColor

Returns stroke color for rubber bands (from global settings)

digitizingStrokeWidth() int

Returns stroke width for rubber bands (from global settings)

disconnectNotify(self, QMetaMethod)
fetchLayerPoint(self, match: QgsPointLocator.Match, layerPoint: QgsPoint) int

Fetches the original point from the source layer if it has the same CRS as the current layer. If topological editing is activated, the points are projected to the current layer CRS.

Return type:

int

Returns:

0 in case of success 1 if not applicable (CRS mismatch / invalid layer) 2 in case of failure

Parameters:
geometryCaptured()
isCapturing(self) bool

Are we currently capturing?

Return type:

bool

Returns:

Is the tool in capture mode?

isSignalConnected(self, QMetaMethod) bool
keyPressEvent(self, e: QKeyEvent)

Intercept key events like Esc or Del to delete the last point

Parameters:

e (QKeyEvent) – key event

lineCaptured()
mapPoint(self, e: QgsMapMouseEvent) QgsPoint

Creates a QgsPoint with ZM support if necessary (according to the WkbType of the current layer). If the point is snapped, then the Z value is derived from the snapped point.

Parameters:

e (QgsMapMouseEvent) – A mouse event

Returns:

a point with ZM support if necessary

mapPoint(self, point: QgsPointXY) -> QgsPoint Creates a QgsPoint with ZM support if necessary (according to the WkbType of the current layer).

Parameters:

point – A point in 2D

Return type:

QgsPoint

Returns:

a point with ZM support if necessary

mode(self) QgsMapToolCapture.CaptureMode

The capture mode

Return type:

QgsMapToolCapture.CaptureMode

Returns:

Capture mode

nextPoint(self, mapPoint: QgsPoint, layerPoint: QgsPoint) int

Converts a map point to layer coordinates

Parameters:

mapPoint (QgsPoint) – the point in map coordinates

param[in,out] layerPoint the point in layer coordinates

Returns:

0 in case of success 1 if the current layer is None 2 if the transformation failed

nextPoint(self, p: QPoint, layerPoint: QgsPoint, mapPoint: QgsPoint) -> int Converts a point to map coordinates and layer coordinates

Parameters:

p – the input point

param[in,out] layerPoint the point in layer coordinates param[in,out] mapPoint the point in map coordinates

Return type:

int

Returns:

0 in case of success 1 if the current layer is None or not a vector layer 2 if the transformation failed

Parameters:

layerPoint (QgsPoint) –

notifyNotEditableLayer(self)

Display a timed message bar noting the active vector layer is not editable.

notifyNotVectorLayer(self)

Display a timed message bar noting the active layer is not vector.

pointCaptured()
points(self) List[QgsPointXY]

List of digitized points

Return type:

List[QgsPointXY]

Returns:

List of points

Deprecated since version QGIS: 3.12 - will be removed in QGIS 4.0. Use the variant returns QgsPoint objects instead of QgsPointXY.

pointsZM(self) List[QgsPoint]

List of digitized points

Return type:

List[QgsPoint]

Returns:

List of points

New in version 3.12.

polygonCaptured()
receivers(self, PYQT_SIGNAL) int
sender(self) QObject
senderSignalIndex(self) int
setAdvancedDigitizingAllowed(self, allowed: bool)

Sets whether functionality of advanced digitizing dock widget is currently allowed. This method is protected because it should be a decision of the map tool and not from elsewhere. sa isAdvancedDigitizingAllowed()

setAutoSnapEnabled(self, enabled: bool)

Sets whether mouse events (press/move/release) should automatically try to snap mouse position This method is protected because it should be a decision of the map tool and not from elsewhere. sa isAutoSnapEnabled()

setCircularDigitizingEnabled(self, enable: bool)

Enable the digitizing with curve

Deprecated since version QGIS: 3.26 use setCurrentCaptureTechnique() instead

Parameters:

enable (bool) –

setCurrentCaptureTechnique(self, technique: Qgis.CaptureTechnique)

Sets the current capture if it is supported by the map tool

New in version 3.26.

Parameters:

technique (Qgis.CaptureTechnique) –

setPoints(self, pointList: Iterable[QgsPointXY])

Set the points on which to work

Parameters:

pointList (Iterable[QgsPointXY]) – A list of points

Deprecated since version QGIS: 3.12 - will be removed in QGIS 4.0. Use the variant which accepts QgsPoint objects instead of QgsPointXY.

setPoints(self, pointList: Iterable[QgsPoint]) Set the points on which to work

Parameters:

pointList – A list of points

New in version 3.12.

setStreamDigitizingEnabled(self, enable: bool)

Toggles the stream digitizing mode.

New in version 3.20.

Deprecated since version QGIS: 3.26 use setCurrentCaptureTechnique() instead

Parameters:

enable (bool) –

setToolName(self, name: str)

Sets the tool’s name.

See also

toolName()

New in version 3.20.

size(self) int

Number of points digitized

Return type:

int

Returns:

Number of points

snappingMatches(self) List[QgsPointLocator.Match]

Returns a list of matches for each point on the captureCurve.

Return type:

List[QgsPointLocator.Match]

startCapturing(self)

Start capturing

stopCapturing(self)

Stop capturing

supportsTechnique(self, technique: Qgis.CaptureTechnique) bool

Returns True if the tool supports the specified capture technique.

New in version 3.20.

Parameters:

technique (Qgis.CaptureTechnique) –

Return type:

bool

takeRubberBand(self) QgsRubberBand

Returns the rubberBand currently owned by this map tool and transfers ownership to the caller.

May be None.

New in version 3.8.

Return type:

QgsRubberBand

timerEvent(self, QTimerEvent)
toCanvasCoordinates(self, point: QgsPointXY) QPoint

Transforms a point from map coordinates to screen coordinates.

toLayerCoordinates(self, layer: QgsMapLayer, point: QPoint) QgsPointXY

Transforms a point from screen coordinates to layer coordinates.

toLayerCoordinates(self, layer: QgsMapLayer, point: QgsPointXY) -> QgsPointXY Transforms a point from map coordinates to layer coordinates.

toLayerCoordinates(self, layer: QgsMapLayer, rect: QgsRectangle) -> QgsRectangle Transforms a rect from map coordinates to layer coordinates.

toLayerCoordinatesV2(self, layer: QgsMapLayer, point: QgsPoint) QgsPoint

Transforms a point from map coordinates to layer coordinates.

Note

This method is available in the Python bindings as toLayerCoordinatesV2.

toMapCoordinates(self, point: QPoint) QgsPointXY

Transforms a point from screen coordinates to map coordinates.

toMapCoordinates(self, layer: QgsMapLayer, point: QgsPointXY) -> QgsPointXY Transforms a point from layer coordinates to map coordinates (which is different in case reprojection is used).

toMapCoordinatesV2(self, layer: QgsMapLayer, point: QgsPoint) QgsPoint

Transforms a point from layer coordinates to map coordinates (which is different in case reprojection is used).

Note

This method is available in the Python bindings as toMapCoordinatesV2.

undo(self, isAutoRepeat: bool = False)

Removes the last vertex from mRubberBand and mCaptureList.

Since QGIS 3.20, if isAutoRepeat is set to True then the undo operation will be treated as a auto repeated undo as if the user has held down the undo key for an extended period of time.

Parameters:

isAutoRepeat (bool = False) –