Class: QgsMapToolCapture¶
Base class for map tools 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)
Class Hierarchy¶
Base classes¶
A |
|
Base class for map tools that edit vector geometry. |
|
Abstract base class for all map tools. |
|
Subclasses¶
Base class for map tools digitizing layer geometries. |
- class qgis.gui.QgsMapToolCapture[source]¶
Bases:
QgsMapToolAdvancedDigitizing- __init__(canvas: QgsMapCanvas | None, cadDockWidget: QgsAdvancedDigitizingDockWidget | None, mode: QgsMapToolCapture.CaptureMode)
constructor
- Parameters:
canvas (Optional[QgsMapCanvas])
cadDockWidget (Optional[QgsAdvancedDigitizingDockWidget])
- class Capabilities¶
- class Capabilities(f: QgsMapToolCapture.Capabilities | QgsMapToolCapture.Capability)
- class Capabilities(a0: QgsMapToolCapture.Capabilities)
Bases:
object
- class Capability¶
Bases:
int
- CaptureLine = 2¶
- class CaptureMode¶
Bases:
int
- CaptureNone = 0¶
- CapturePoint = 1¶
- CapturePolygon = 3¶
- class CaptureTechnique(*values)¶
Bases:
IntEnumCapture technique.
Added in version 3.26.
StraightSegments: Default capture mode - capture occurs with straight line segmentsCircularString: Capture in circular stringsStreaming: Streaming points digitizing mode (points are automatically added as the mouse cursor moves).Shape: Digitize shapes.
- NoCapabilities = 1¶
- SupportsCurves = 2¶
- ValidateGeometries = 4¶
- addCurve(self, c: QgsCurve | None) int[source]¶
Adds a whole curve (e.g. circularstring) to the captured geometry. Curve must be in map CRS
- Parameters:
c (Optional[QgsCurve])
- Return type:
int
- addVertex(self, point: QgsPointXY) int[source]¶
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)
- virtual capabilities(self) QgsMapToolCapture.Capabilities[source]¶
Returns flags containing the supported capabilities
- Return type:
- captureCurve(self) QgsCompoundCurve | None[source]¶
Gets the capture curve
- Return type:
Optional[QgsCompoundCurve]
- Returns:
Capture curve
- currentCaptureTechnique(self) Qgis.CaptureTechnique[source]¶
Returns the active capture technique
Added in version 3.32.
- Return type:
- fetchLayerPoint(self, match: QgsPointLocator.Match, layerPoint: QgsPoint) int[source]¶
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:
match (QgsPointLocator.Match)
layerPoint (QgsPoint)
- virtual geometryCaptured(self, geometry: QgsGeometry)[source]¶
Called when the geometry is captured.
A more specific handler is also called afterwards (
pointCaptured(),lineCaptured()orpolygonCaptured()).Added in version 3.26.
- Parameters:
geometry (QgsGeometry)
- isCapturing(self) bool[source]¶
Are we currently capturing?
- Return type:
bool
- Returns:
Is the tool in capture mode?
- virtual keyPressEvent(self, e: QKeyEvent | None)[source]¶
Intercept key events like Esc or Del to delete the last point
- Parameters:
e (Optional[QKeyEvent]) – key event
- virtual lineCaptured(self, line: QgsCurve | None)[source]¶
Called when a line is captured
The generic
geometryCaptured()method will be called immediately before this line-specific method.Added in version 3.26.
- Parameters:
line (Optional[QgsCurve])
- mapPoint(self, e: QgsMapMouseEvent) QgsPoint[source]¶
Creates a
QgsPointwith 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 aQgsPointwith ZM support if necessary (according to the WkbType of the current layer).- Parameters:
point – A point in 2D
- Return type:
- Returns:
a point with ZM support if necessary
- mode(self) QgsMapToolCapture.CaptureMode[source]¶
The capture mode
- Return type:
- Returns:
Capture mode
- nextPoint(self, mapPoint: QgsPoint, layerPoint: QgsPoint) int[source]¶
Converts a map point to layer coordinates
- Parameters:
- Returns:
0 in case of success 1 if the current layer is
None2 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
layerPoint – the point in layer coordinates
mapPoint – the point in map coordinates
- Return type:
int
- Returns:
0 in case of success 1 if the current layer is
Noneor not a vector layer 2 if the transformation failed
- virtual pointCaptured(self, point: QgsPoint)[source]¶
Called when a point is captured.
The generic
geometryCaptured()method will be called immediately before this point-specific method.Added in version 3.26.
- Parameters:
point (QgsPoint)
- points(self) List[QgsPointXY]¶
List of digitized points
- Return type:
- Returns:
List of points
Deprecated since version 3.12: Will be removed in QGIS 4.0. Use the variant returns
QgsPointobjects instead ofQgsPointXY.
- virtual polygonCaptured(self, polygon: QgsCurvePolygon | None)[source]¶
Called when a polygon is captured.
The generic
geometryCaptured()method will be called immediately before this polygon-specific method.Added in version 3.26.
- Parameters:
polygon (Optional[QgsCurvePolygon])
- setCircularDigitizingEnabled(self, enable: bool)[source]¶
Enable the digitizing with curve
Deprecated since version 3.26: Use
setCurrentCaptureTechnique()instead.- Parameters:
enable (bool)
- setCurrentCaptureTechnique(self, technique: Qgis.CaptureTechnique)[source]¶
Sets the current capture if it is supported by the map tool
Added in version 3.26.
- Parameters:
technique (Qgis.CaptureTechnique)
- setPoints(self, pointList: Iterable[QgsPointXY])[source]¶
Set the points on which to work
- Parameters:
pointList (Iterable[QgsPointXY]) – A list of points
Deprecated since version 3.12: Will be removed in QGIS 4.0. Use the variant which accepts
QgsPointobjects instead ofQgsPointXY.setPoints(self, pointList: Iterable[QgsPoint]) Set the points on which to work
- Parameters:
pointList – A list of points
Added in version 3.12.
- setStreamDigitizingEnabled(self, enable: bool)[source]¶
Toggles the stream digitizing mode.
Added in version 3.20.
Deprecated since version 3.26: Use
setCurrentCaptureTechnique()instead.- Parameters:
enable (bool)
- snappingMatches(self) List[QgsPointLocator.Match]¶
Returns a list of matches for each point on the captureCurve.
- Return type:
- virtual supportsTechnique(self, technique: Qgis.CaptureTechnique) bool[source]¶
Returns
Trueif the tool supports the specified capturetechnique.Added in version 3.20.
- Parameters:
technique (Qgis.CaptureTechnique)
- Return type:
bool
- takeRubberBand(self) QgsRubberBand | None[source]¶
Returns the rubberBand currently owned by this map tool and transfers ownership to the caller.
May be
None.Added in version 3.8.
- Return type:
Optional[QgsRubberBand]
- undo(self, isAutoRepeat: bool = False)[source]¶
Removes the last vertex from mRubberBand and mCaptureList.
Since QGIS 3.20, if
isAutoRepeatis set toTruethen 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)