Class: QgsMapToolDigitizeFeature

class qgis.gui.QgsMapToolDigitizeFeature(canvas: QgsMapCanvas, cadDockWidget: QgsAdvancedDigitizingDockWidget, mode: QgsMapToolCapture.CaptureMode = QgsMapToolCapture.CaptureNone)

Bases: QgsMapToolCapture

QgsMapToolDigitizeFeature is a map tool to digitize a feature geometry

Parameters
  • canvas (QgsMapCanvas) – the map canvas

  • cadDockWidget (QgsAdvancedDigitizingDockWidget) – widget to setup advanced digitizing parameters

  • mode (QgsMapToolCapture.CaptureMode = QgsMapToolCapture.CaptureNone) – type of geometry to capture (point/line/polygon), QgsMapToolCapture.CaptureNone to autodetect geometry

This tool digitizes geometry of new point/line/polygon features on already existing vector layers Once the map tool is enabled, user can digitize the feature geometry. A signal will then be emitted.

Methods

activate

addTopologicalPoints

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

addVertex

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

cadCanvasReleaseEvent

param e

capabilities

rtype

QgsMapToolCapture.Capabilities

checkGeometryType

Check if CaptureMode matches layer type.

childEvent

closePolygon

Close an open polygon

connectNotify

createGeometryRubberBand

createRubberBand

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

currentVectorLayer

Returns the current vector layer of the map canvas or 0

customEvent

deactivate

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.

isCapturing

Are we currently capturing?

isSignalConnected

mapPoint

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

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.

points

List of digitized points

pointsZM

List of digitized points

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.

setCheckGeometryType

Check if CaptureMode matches layer type.

setLayer

Change the layer edited by the map tool

setPoints

Set the points on which to work

size

Number of points digitized

startCapturing

Start capturing

stopCapturing

Stop capturing

timerEvent

toCanvasCoordinates

transformation from map coordinates to screen coordinates

toLayerCoordinates

transformation from screen coordinates to layer’s coordinates

toMapCoordinates

transformation from screen coordinates to map coordinates

toMapCoordinatesV2

transformation from layer’s coordinates to map coordinates (which is different in case reprojection is used)

undo

Removes the last vertex from mRubberBand and mCaptureList

Signals

digitizingCompleted

Emitted whenever the digitizing has been successfully completed

digitizingFinished

Emitted whenever the digitizing has been ended without digitizing any feature [signal]

activate(self)
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)

Returns

0 in case of success, 1 if current layer is not a vector layer, 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.

New in version 2.14.

cadCanvasReleaseEvent(self, e: QgsMapMouseEvent)
Parameters

e (QgsMapMouseEvent) –

capabilities(self)QgsMapToolCapture.Capabilities
Return type

QgsMapToolCapture.Capabilities

checkGeometryType(self) → bool

Check if CaptureMode matches layer type. Default is true.

New in version 3.0.

Return type

bool

childEvent(self, QChildEvent)
closePolygon(self)

Close an open polygon

connectNotify(self, QMetaMethod)
createGeometryRubberBand(self, geometryType: QgsWkbTypes.GeometryType = QgsWkbTypes.LineGeometry, alternativeBand: bool = False)QgsGeometryRubberBand
createRubberBand(self, geometryType: QgsWkbTypes.GeometryType = QgsWkbTypes.LineGeometry, 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.

currentVectorLayer(self)QgsVectorLayer

Returns the current vector layer of the map canvas or 0

customEvent(self, QEvent)
deactivate(self)
digitizingCompleted

Emitted whenever the digitizing has been successfully completed

Parameters

feature (QgsFeature) – the new digitized feature [signal]

digitizingFillColor() → QColor

Returns fill color for rubber bands (from global settings)

digitizingFinished

Emitted whenever the digitizing has been ended without digitizing any feature [signal]

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.

Returns

0 in case of success, 1 if not applicable (CRS mismatch), 2 in case of failure

New in version 2.14.

isCapturing(self) → bool

Are we currently capturing?

Returns

Is the tool in capture mode?

isSignalConnected(self, QMetaMethod) → bool
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 took from the snapped point.

Parameters

e – A mouse event

Returns

a point with ZM support if necessary

New in version 3.0.

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

Returns

a point with ZM support if necessary

New in version 3.0.

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

Converts a map point to layer coordinates

Parameters

mapPoint – 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 or not a vector layer 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

Returns

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

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.

points(self) → List[QgsPointXY]

List of digitized points

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

Returns

List of points

New in version 3.12.

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

New in version 3.0.

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

New in version 3.0.

setCheckGeometryType(self, checkGeometryType: bool)

Check if CaptureMode matches layer type. Default is true.

New in version 3.0.

Parameters

checkGeometryType (bool) –

setLayer(self, vl: QgsMapLayer)

Change the layer edited by the map tool

Parameters

vl (QgsMapLayer) – the layer to be edited by the map tool

setPoints(self, pointList: Iterable[QgsPointXY])

Set the points on which to work

Parameters

pointList – 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.

size(self) → int

Number of points digitized

Returns

Number of points

startCapturing(self)

Start capturing

stopCapturing(self)

Stop capturing

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

transformation from map coordinates to screen coordinates

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

transformation from screen coordinates to layer’s coordinates

toLayerCoordinates(self, layer: QgsMapLayer, point: QgsPointXY) -> QgsPointXY transformation from map coordinates to layer’s coordinates

toLayerCoordinates(self, layer: QgsMapLayer, rect: QgsRectangle) -> QgsRectangle trnasformation of the rect from map coordinates to layer’s coordinates

toMapCoordinates(self, point: QPoint)QgsPointXY

transformation from screen coordinates to map coordinates

toMapCoordinates(self, layer: QgsMapLayer, point: QgsPointXY) -> QgsPointXY transformation from layer’s coordinates to map coordinates (which is different in case reprojection is used)

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

transformation from layer’s coordinates to map coordinates (which is different in case reprojection is used)

Note

available in Python bindings as toMapCoordinatesV2

undo(self)

Removes the last vertex from mRubberBand and mCaptureList