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. |
Enums
Capture technique. |
Methods
Adds a whole curve (e.g. circularstring) to the captured geometry. |
|
Adds a point to the rubber band (in map coordinates) and to the capture list (in layer coordinates) |
|
Gets the capture curve |
|
Clear capture curve. |
|
Close an open polygon |
|
Returns the active capture technique |
|
Clean a temporary rubberband |
|
Fetches the original point from the source layer if it has the same CRS as the current layer. |
|
Are we currently capturing? |
|
Creates a |
|
The capture mode |
|
Converts a map point to layer coordinates |
|
List of digitized points |
|
List of digitized points |
|
Enable the digitizing with curve |
|
Sets the current capture if it is supported by the map tool |
|
Set the points on which to work |
|
Toggles the stream digitizing mode. |
|
Number of points digitized |
|
Returns a list of matches for each point on the captureCurve. |
|
Start capturing |
|
Stop capturing |
|
Returns the rubberBand currently owned by this map tool and transfers ownership to the caller. |
|
Removes the last vertex from mRubberBand and mCaptureList. |
Virtual Methods
In PyQGIS, only methods marked as virtual
can be safely overridden in a Python subclass of QgsMapToolCapture. See the FAQ for more details.
Returns flags containing the supported capabilities |
|
Called when the geometry is captured. |
|
Intercept key events like Esc or Del to delete the last point |
|
Called when a line is captured |
|
Called when a point is captured. |
|
Called when a polygon is captured. |
|
Returns |
Attributes
- 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:
IntEnum
Capture 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
- Parameters:
point (
QgsPointXY
)
- addVertex(self, mapPoint: QgsPointXY, match: QgsPointLocator.Match) int [source]
Variant to supply more information in the case of snapping
- Parameters:
mapPoint (
QgsPointXY
) – The vertex to add in map coordinatesmatch (QgsPointLocator.Match) – Data about the snapping match. Can be an invalid match, if point not snapped.
- Return type:
int
- 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
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- Return type:
- Returns:
a point with ZM support if necessary
- mapPoint(self, point: QgsPointXY) QgsPoint [source]
Creates a
QgsPoint
with ZM support if necessary (according to the WkbType of the current layer).- Parameters:
point (
QgsPointXY
) – 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
- nextPoint(self, p: QPoint, layerPoint: QgsPoint, mapPoint: QgsPoint) int [source]
Converts a point to map coordinates and layer coordinates
- 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:
List[QgsPointXY]
- Returns:
List of points
Deprecated since version 3.12: Will be removed in QGIS 4.0. Use the variant returns
QgsPoint
objects instead ofQgsPointXY
.
- pointsZM(self) List[QgsPoint] [source]¶
List of digitized points
- Return type:
List[QgsPoint]
- Returns:
List of points
Added in version 3.12.
- 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
QgsPoint
objects instead ofQgsPointXY
.
- setPoints(self, pointList: Iterable[QgsPoint])[source]
Set the points on which to work
- Parameters:
pointList (Iterable[QgsPoint]) – 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:
List[QgsPointLocator.Match]
- virtual supportsTechnique(self, technique: Qgis.CaptureTechnique) bool [source]¶
Returns
True
if 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
isAutoRepeat
is set toTrue
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)