Class: QgsMapToolExtent

class qgis.gui.QgsMapToolExtent

Bases: QgsMapTool

A map tool that emits an extent from a rectangle drawn onto the map canvas.

QgsMapToolExtent(canvas: QgsMapCanvas) constructor

Methods

activate

canvasMoveEvent

param e:

canvasPressEvent

param e:

canvasReleaseEvent

param e:

childEvent

clearRubberBand

Removes the tool's rubber band from the canvas.

connectNotify

customEvent

deactivate

disconnectNotify

extent

Returns the current extent drawn onto the canvas.

flags

rtype:

QgsMapTool.Flags

isSignalConnected

layer

Returns the map layer with the matching ID, or None if no layers could be found.

ratio

Returns the current fixed aspect ratio to be used when dragging extent onto the canvas.

receivers

sender

senderSignalIndex

setRatio

Sets a fixed aspect ratio to be used when dragging extent onto the canvas.

setToolName

Sets the tool's name.

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

Signals

extentChanged

pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL

activate(self)
canvasMoveEvent(self, e: QgsMapMouseEvent)
Parameters:

e (QgsMapMouseEvent) –

canvasPressEvent(self, e: QgsMapMouseEvent)
Parameters:

e (QgsMapMouseEvent) –

canvasReleaseEvent(self, e: QgsMapMouseEvent)
Parameters:

e (QgsMapMouseEvent) –

childEvent(self, QChildEvent)
clearRubberBand(self)

Removes the tool’s rubber band from the canvas.

New in version 3.20.

connectNotify(self, QMetaMethod)
customEvent(self, QEvent)
deactivate(self)
disconnectNotify(self, QMetaMethod)
extent(self) QgsRectangle

Returns the current extent drawn onto the canvas.

Return type:

QgsRectangle

extentChanged

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...) –

  • revision (int = ...) –

  • arguments (Sequence = ...) –

Return type:

PYQT_SIGNAL

flags(self) QgsMapTool.Flags
Return type:

QgsMapTool.Flags

isSignalConnected(self, QMetaMethod) bool
layer(self, id: str) QgsMapLayer

Returns the map layer with the matching ID, or None if no layers could be found.

This method searches both layers associated with the map canvas (see QgsMapCanvas.layers()) and layers from the QgsProject associated with the canvas. It can be used to resolve layer IDs to layers which may be visible in the canvas, but not associated with a QgsProject.

New in version 3.22.

ratio(self) QSize

Returns the current fixed aspect ratio to be used when dragging extent onto the canvas. If the aspect ratio isn’t fixed, the width and height will be set to zero.

Return type:

QSize

receivers(self, PYQT_SIGNAL) int
sender(self) QObject
senderSignalIndex(self) int
setRatio(self, ratio: QSize)

Sets a fixed aspect ratio to be used when dragging extent onto the canvas. To unset a fixed aspect ratio, set the width and height to zero.

Parameters:

ratio (QSize) – aspect ratio’s width and height

setToolName(self, name: str)

Sets the tool’s name.

See also

toolName()

New in version 3.20.

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.