Class: QgsMapCanvas¶
- class qgis.gui.QgsMapCanvas¶
Bases:
PyQt5.QtWidgets.QGraphicsView
,QgsExpressionContextGenerator
Map canvas is a class for displaying all GIS data types on a canvas.
QgsMapCanvas(parent: QWidget = None) Constructor
Methods
Returns
True
if the specifiedinteraction
is currently permitted on the canvas.Returns a list of all annotation items in the canvas.
Returns
True
if annotations are visible within the map canvas.True
if antialiasing is enabledReturns the map renderer cache, if caching is enabled.
Read property of QColor bgColor.
Gets map center, in geographical coordinates
Make sure to remove any rendered images from cache (does nothing if cache is not enabled)
Clears the list of extents and sets current extent as first item
- rtype:
QgsExpressionContext
returns current layer (set by legend widget)
Creates a new scope which contains default variables and functions relating to the map canvas.
- param e:
- param event:
Emits the extentsChanged signal when appropriate.
used to determine if anti-aliasing is enabled or not
sets map tile rendering flag
- param e:
Returns a reference to the expression context scope for the map canvas.
Returns the current zoom extent of the map canvas
Causes a set of features with matching
ids
from a vectorlayer
to flash within the canvas.Causes a set of
geometries
to flash within the canvas.Freeze/thaw the map canvas.
Returns the combined extent for all layers on the map canvas.
Gets the current coordinate transform
Installs an interaction
blocker
onto the canvas, which may prevent certain map canvas interactions from occurring.Check whether images of rendered layers are curerently being cached
Find out whether rendering is in progress
Returns
True
if canvas is frozen.Check whether the layers are rendered in parallel or sequentially
- param e:
- param e:
Returns global labeling engine settings from the internal map settings
Gets access to the labeling results (may be
None
).Returns the map layer at position index in the layer stack
Returns number of layers on the map.
This slot is connected to the visibility change of one or more layers
Returns the stored overrides of styles for layers.
Returns the list of layers shown within the map canvas.
Returns the magnification factor
Gets access to properties used for map rendering
Returns the currently active tool
Convenience function for returning the current canvas map units.
Returns the mapUnitsPerPixel (map units per pixel) for the canvas
Find out how often map preview should be updated while it is being rendered (in milliseconds)
- param e:
returns last position of mouse cursor
- param e:
- param e:
- param e:
called when panning is in action, reset indicates end of panning
- param e:
Called when mouse is moving and pan is activated
Ends pan action and redraws the canvas.
Centers canvas extent to feature ids
Pan to the selected features of current ayer keeping same extent.
Returns
True
if canvas map preview jobs (low priority render jobs which render portions of the view just outside of the canvas extent, to allow preview of these out-of-canvas areas when panning or zooming out the map) are enabled for the canvas.Returns the current preview mode for the map canvas.
Returns whether a preview mode is enabled for the map canvas
Returns the project linked to this canvas.
Returns the associated project's full extent, in the canvas' CRS.
called to read map canvas settings from project
Clears all cached images and redraws all layers.
Repaints the canvas map
Reload all layers (including refreshing layer properties from their data sources), clears the cache and refreshes the canvas.
Removes an interaction
blocker
from the canvas.Returns
True
if canvas render is disabled as a result of user disabling renders via the GUI.Gets access to the rendered item results (may be
None
), which includes the results of rendering annotation items in the canvas map.- param e:
Gets the current map canvas rotation in clockwise degrees
Save the contents of the map canvas to disk as an image
Returns the last reported scale of the canvas.
Returns whether the scale is locked, so zooming can be performed using magnication.
scrollContentsBy
Receives signal about selection change, and pass it on with layer info
Returns color for selected features
Sets whether annotations are
visible
in the canvas.Set whether to cache images of rendered layers
Write property of QColor bgColor.
Set the center of the map canvas, in geographical coordinates
- param layer:
Sets destination coordinate reference system
Sets an expression context scope for the map canvas.
Sets the extent of the map canvas to the specified rectangle.
Sets global labeling engine settings in the internal map settings
Sets the stored overrides of styles for rendering layers.
Sets the list of
layers
that should be shown in the canvas.Sets the factor of magnification to apply to the map canvas.
Resets the
flags
for the canvas' map settings.Sets the map tool currently being used on the canvas
Set how often map preview should be updated while it is being rendered (in milliseconds)
Set whether the layers are rendered in parallel or sequentially
Sets whether canvas map preview jobs (low priority render jobs which render portions of the view just outside of the canvas extent, to allow preview of these out-of-canvas areas when panning or zooming out the map) are
enabled
for the canvas.Sets a preview mode for the map canvas.
Enables a preview mode for the map canvas
Sets the
project
linked to this canvas.Sets the canvas to the specified
extent
.Sets whether a user has disabled canvas renders via the GUI.
Set the rotation of the map canvas in clockwise degrees
Lock the scale, so zooming can be performed using magnication
Sets the segmentation tolerance applied when rendering curved geometries
Sets segmentation tolerance type (maximum angle or maximum difference between curve and approximation)
Set color of selected vector features
Assign an instance of snapping utils to the map canvas.
Sets the temporal
controller
for this canvas.Set datetime
range
for the map canvas.Sets a map
theme
to show in the canvas.Sets wheel zoom factor (should be greater than 1)
Sets the
range
of z-values which will be visible in the map.Set a list of resolutions (map units per pixel) to which to "snap to" when zooming the map
- param event:
Returns snapping utility class that is associated with map canvas.
stop rendering (if there is any right now)
Gets access to the temporal controller that will be used to update the canvas temporal range.
Returns map canvas datetime range.
Returns the map's theme shown in the canvas, if set.
Unset the current map tool or last non zoom tool
called on resize or changed extent to notify canvas items to change their rectangle
Emits signal scaleChanged to update scale in main window
- param event:
Blocks until the rendering job has finished.
- param e:
called to write map canvas settings to project
Returns the range of z-values which will be visible in the map.
Zoom with the factor supplied.
Zoom in with fixed factor
Returns the zoom in factor.
Zoom out with fixed factor
Returns the zoom in factor.
- rtype:
List[float]
Zooms the canvas to a specific
scale
.Zooms to feature extent.
Set canvas extent to the bounding box of a set of features
Zoom to the full extent of all layers currently visible in the canvas.
Zoom to the next extent (view)
Zoom to the previous extent (view)
Zoom to the full extent the project associated with this canvas.
Zoom to the extent of the selected features of provided map layer.
Zooms in/out with a given center
Signals
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
- actionEvent(self, QActionEvent)¶
- allowInteraction(self, interaction: QgsMapCanvasInteractionBlocker.Interaction) bool ¶
Returns
True
if the specifiedinteraction
is currently permitted on the canvas.New in version 3.14.
- Parameters:
interaction (QgsMapCanvasInteractionBlocker.Interaction) –
- Return type:
bool
- annotationItems(self) List[QgsMapCanvasAnnotationItem] ¶
Returns a list of all annotation items in the canvas.
New in version 3.0.
- Return type:
- annotationsVisible(self) bool ¶
Returns
True
if annotations are visible within the map canvas.See also
New in version 3.0.
- Return type:
bool
- antiAliasingEnabled(self) bool ¶
True
if antialiasing is enabled- Return type:
bool
- cache(self) QgsMapRendererCache ¶
Returns the map renderer cache, if caching is enabled.
See also
See also
New in version 3.32.
- Return type:
- canvasColor(self) QColor ¶
Read property of QColor bgColor.
- Return type:
QColor
- canvasColorChanged¶
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
- center(self) QgsPointXY ¶
Gets map center, in geographical coordinates
New in version 2.8.
- Return type:
- changeEvent(self, QEvent)¶
- childEvent(self, QChildEvent)¶
- clearCache(self)¶
Make sure to remove any rendered images from cache (does nothing if cache is not enabled)
New in version 2.4.
- clearExtentHistory(self)¶
Clears the list of extents and sets current extent as first item
- closeEvent(self, QCloseEvent)¶
- connectNotify(self, QMetaMethod)¶
- contextMenuAboutToShow¶
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
- contextMenuEvent(self, QContextMenuEvent)¶
- create(self, window: PyQt5.sip.voidptr = 0, initializeWindow: bool = True, destroyOldWindow: bool = True)¶
- createExpressionContext(self) QgsExpressionContext ¶
- Return type:
- currentLayer(self) QgsMapLayer ¶
returns current layer (set by legend widget)
- Return type:
- currentLayerChanged¶
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
- customEvent(self, QEvent)¶
- defaultExpressionContextScope(self) QgsExpressionContextScope ¶
Creates a new scope which contains default variables and functions relating to the map canvas.
See also
See also
New in version 3.4.
- Return type:
- destinationCrsChanged¶
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
- destroy(self, destroyWindow: bool = True, destroySubWindows: bool = True)¶
- disconnectNotify(self, QMetaMethod)¶
- dragEnterEvent(self, e: QDragEnterEvent)¶
- Parameters:
e (QDragEnterEvent) –
- dragLeaveEvent(self, QDragLeaveEvent)¶
- dragMoveEvent(self, QDragMoveEvent)¶
- drawBackground(self, QPainter, QRectF)¶
- drawForeground(self, QPainter, QRectF)¶
- drawFrame(self, QPainter)¶
- dropEvent(self, event: QDropEvent)¶
- Parameters:
event (QDropEvent) –
- emitExtentsChanged(self)¶
Emits the extentsChanged signal when appropriate.
New in version 3.30.
- enableAntiAliasing(self, flag: bool)¶
used to determine if anti-aliasing is enabled or not
- Parameters:
flag (bool) –
- enableMapTileRendering(self, flag: bool)¶
sets map tile rendering flag
- Parameters:
flag (bool) –
- enterEvent(self, QEvent)¶
- event(self, e: QEvent) bool ¶
- Parameters:
e (QEvent) –
- Return type:
bool
- eventFilter(self, QObject, QEvent) bool ¶
- expressionContextScope(self) QgsExpressionContextScope ¶
Returns a reference to the expression context scope for the map canvas. This scope is injected into the expression context used for rendering the map, and can be used to apply specific variable overrides for expression evaluation for the map canvas render.
See also
See also
New in version 2.12.
- Return type:
- extent(self) QgsRectangle ¶
Returns the current zoom extent of the map canvas
- Return type:
- extentsChanged¶
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
- flashFeatureIds(self, layer: QgsVectorLayer, ids: object, startColor: QColor | Qt.GlobalColor | QGradient = QColor(255, 0, 0, 255), endColor: QColor | Qt.GlobalColor | QGradient = QColor(255, 0, 0, 0), flashes: int = 3, duration: int = 500)¶
Causes a set of features with matching
ids
from a vectorlayer
to flash within the canvas.The
startColor
andendColor
can be specified, along with the number offlashes
andduration
of each flash (in milliseconds).Note
If the features or geometries are already available,
flashGeometries()
is much more efficient.See also
New in version 3.0.
- Parameters:
layer (QgsVectorLayer) –
ids (object) –
startColor (Union[QColor) –
endColor (Union[QColor) –
flashes (int = 3) –
duration (int = 500) –
- flashGeometries(self, geometries: Iterable[QgsGeometry], crs: QgsCoordinateReferenceSystem = QgsCoordinateReferenceSystem(), startColor: QColor | Qt.GlobalColor | QGradient = QColor(255, 0, 0, 255), endColor: QColor | Qt.GlobalColor | QGradient = QColor(255, 0, 0, 0), flashes: int = 3, duration: int = 500)¶
Causes a set of
geometries
to flash within the canvas.If
crs
is a valid coordinate reference system, the geometries will be automatically transformed from this CRS to the canvas CRS.The
startColor
andendColor
can be specified, along with the number offlashes
andduration
of each flash (in milliseconds).See also
New in version 3.0.
- Parameters:
geometries (Iterable[QgsGeometry]) –
crs (
QgsCoordinateReferenceSystem
= QgsCoordinateReferenceSystem()) –startColor (Union[QColor) –
endColor (Union[QColor) –
flashes (int = 3) –
duration (int = 500) –
- focusInEvent(self, QFocusEvent)¶
- focusNextChild(self) bool ¶
- focusNextPrevChild(self, bool) bool ¶
- focusOutEvent(self, QFocusEvent)¶
- focusPreviousChild(self) bool ¶
- freeze(self, frozen: bool = True)¶
Freeze/thaw the map canvas. This is used to prevent the canvas from responding to events while layers are being added/removed etc.
- Parameters:
frozen (bool = True) – Boolean specifying if the canvas should be frozen (
True
) or thawed (False
). Default isTrue
.
See also
See also
setRenderFlag()
whilesetRenderFlag()
should only be used when users disable rendering via GUI.
- fullExtent(self) QgsRectangle ¶
Returns the combined extent for all layers on the map canvas.
This method returns the combined extent for all layers which are currently visible in the map canvas. The returned extent will be in the same CRS as the map canvas.
See also
- Return type:
- getCoordinateTransform(self) QgsMapToPixel ¶
Gets the current coordinate transform
- Return type:
- hideEvent(self, QHideEvent)¶
- initPainter(self, QPainter)¶
- initStyleOption(self, QStyleOptionFrame)¶
- inputMethodEvent(self, QInputMethodEvent)¶
- installInteractionBlocker(self, blocker: QgsMapCanvasInteractionBlocker)¶
Installs an interaction
blocker
onto the canvas, which may prevent certain map canvas interactions from occurring.The caller retains ownership of
blocker
, and must correctly callremoveInteractionBlocker()
before deleting the object.See also
See also
New in version 3.14.
- Parameters:
blocker (QgsMapCanvasInteractionBlocker) –
- isCachingEnabled(self) bool ¶
Check whether images of rendered layers are curerently being cached
See also
See also
New in version 2.4.
- Return type:
bool
- isDrawing(self) bool ¶
Find out whether rendering is in progress
- Return type:
bool
- isFrozen(self) bool ¶
Returns
True
if canvas is frozen.See also
have been halted programmatically, while
renderFlag()
should be used to determine whether a user has disabled rendering via GUI.See also
- Return type:
bool
- isParallelRenderingEnabled(self) bool ¶
Check whether the layers are rendered in parallel or sequentially
New in version 2.4.
- Return type:
bool
- isSignalConnected(self, QMetaMethod) bool ¶
- keyPressEvent(self, e: QKeyEvent)¶
- Parameters:
e (QKeyEvent) –
- keyPressed¶
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
- keyReleaseEvent(self, e: QKeyEvent)¶
- Parameters:
e (QKeyEvent) –
- keyReleased¶
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
- labelingEngineSettings(self) QgsLabelingEngineSettings ¶
Returns global labeling engine settings from the internal map settings
New in version 3.0.
- Return type:
- labelingResults(self, allowOutdatedResults: bool = True) QgsLabelingResults ¶
Gets access to the labeling results (may be
None
).Since QGIS 3.20, if the
allowOutdatedResults
flag isFalse
then outdated labeling results (e.g. as a result of an ongoing canvas render) will not be returned, and insteadNone
will be returned.New in version 2.4.
- Parameters:
allowOutdatedResults (bool = True) –
- Return type:
- layer(self, index: int) QgsMapLayer ¶
Returns the map layer at position index in the layer stack
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
layers()
) and layers from theQgsProject
associated with the canvas (which is current theQgsProject.instance()
). It can be used to resolve layer IDs to layers which may be visible in the canvas, but not associated with aQgsProject
.New in version 3.22.
- Parameters:
index (int) –
- Return type:
- layerCount(self) int ¶
Returns number of layers on the map.
- Return type:
int
- layerStateChange(self)¶
This slot is connected to the visibility change of one or more layers
- layerStyleOverrides(self) Dict[str, str] ¶
Returns the stored overrides of styles for layers.
See also
New in version 2.12.
- Return type:
Dict[str, str]
- layerStyleOverridesChanged¶
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
- layers(self, expandGroupLayers: bool = False) List[QgsMapLayer] ¶
Returns the list of layers shown within the map canvas.
Since QGIS 3.24, if the
expandGroupLayers
option isTrue
then group layers will be converted to all their child layers.See also
- Parameters:
expandGroupLayers (bool = False) –
- Return type:
List[QgsMapLayer]
- layersChanged¶
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
- leaveEvent(self, QEvent)¶
- magnificationChanged¶
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
- magnificationFactor(self) float ¶
Returns the magnification factor
New in version 2.16.
- Return type:
float
- mapCanvasRefreshed¶
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
- mapRefreshCanceled¶
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
- mapSettings(self) QgsMapSettings ¶
Gets access to properties used for map rendering
New in version 2.4.
- Return type:
- mapTool(self) QgsMapTool ¶
Returns the currently active tool
- Return type:
- mapToolSet¶
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
- mapUnits(self) Qgis.DistanceUnit ¶
Convenience function for returning the current canvas map units. The map units are dictated by the canvas’
destinationCrs()
map units.- Return type:
- mapUnitsPerPixel(self) float ¶
Returns the mapUnitsPerPixel (map units per pixel) for the canvas
- Return type:
float
- mapUpdateInterval(self) int ¶
Find out how often map preview should be updated while it is being rendered (in milliseconds)
New in version 2.4.
- Return type:
int
- messageEmitted¶
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
- metric(self, QPaintDevice.PaintDeviceMetric) int ¶
- mouseDoubleClickEvent(self, e: QMouseEvent)¶
- Parameters:
e (QMouseEvent) –
- mouseLastXY(self) QPoint ¶
returns last position of mouse cursor
- Return type:
QPoint
- mouseMoveEvent(self, e: QMouseEvent)¶
- Parameters:
e (QMouseEvent) –
- mousePressEvent(self, e: QMouseEvent)¶
- Parameters:
e (QMouseEvent) –
- mouseReleaseEvent(self, e: QMouseEvent)¶
- Parameters:
e (QMouseEvent) –
- moveCanvasContents(self, reset: bool = False)¶
called when panning is in action, reset indicates end of panning
- Parameters:
reset (bool = False) –
- moveEvent(self, QMoveEvent)¶
- nativeEvent(self, Union[QByteArray, bytes, bytearray], PyQt5.sip.voidptr) Tuple[bool, int] ¶
- paintEvent(self, e: QPaintEvent)¶
- Parameters:
e (QPaintEvent) –
- panAction(self, event: QMouseEvent)¶
Called when mouse is moving and pan is activated
- Parameters:
event (QMouseEvent) –
- panActionEnd(self, releasePoint: QPoint)¶
Ends pan action and redraws the canvas.
- Parameters:
releasePoint (QPoint) –
- panDistanceBearingChanged¶
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
- panToFeatureIds(self, layer: QgsVectorLayer, ids: object, alwaysRecenter: bool = True)¶
Centers canvas extent to feature ids
- Parameters:
layer (QgsVectorLayer) – the vector layer
ids (object) – the feature ids
alwaysRecenter (bool = True) – if
False
, the canvas is recentered only if the bounding box is not contained within the current extent
- panToSelected(self, layer: QgsMapLayer = None)¶
Pan to the selected features of current ayer keeping same extent.
panToSelected(self, layers: Iterable[QgsMapLayer]) Pan to the combined extent of the selected features of all provided (vector) layers.
- Parameters:
layers – A list of layers
New in version 3.18.
- Parameters:
layer (
QgsMapLayer
= None) –
- previewJobsEnabled(self) bool ¶
Returns
True
if canvas map preview jobs (low priority render jobs which render portions of the view just outside of the canvas extent, to allow preview of these out-of-canvas areas when panning or zooming out the map) are enabled for the canvas.See also
New in version 3.0.
- Return type:
bool
- previewMode(self) QgsPreviewEffect.PreviewMode ¶
Returns the current preview mode for the map canvas. This setting only has an effect if previewModeEnabled is
True
.- Return type:
- Returns:
preview mode for map canvas
See also
See also
New in version 2.3.
- previewModeEnabled(self) bool ¶
Returns whether a preview mode is enabled for the map canvas
- Return type:
bool
- Returns:
True
if a preview mode is currently enabled
See also
See also
New in version 2.3.
- project(self) QgsProject ¶
Returns the project linked to this canvas. The returned value may be
None
.New in version 3.14.
- Return type:
- projectExtent(self) QgsRectangle ¶
Returns the associated project’s full extent, in the canvas’ CRS.
This method returns the full extent for the project associated with this canvas. Unlike
fullExtent()
, this method does NOT consider which layers are actually visible in the map canvas.See also
New in version 3.20.
- Return type:
- readProject(self, QDomDocument)¶
called to read map canvas settings from project
- receivers(self, PYQT_SIGNAL) int ¶
- redrawAllLayers(self)¶
Clears all cached images and redraws all layers.
Note
Unlike
refreshAllLayers()
, this does NOT reload layers themselves, and accordingly is more “lightweight”. Use this method when only an update of the layer’s renderers is required.New in version 3.10.
- refresh(self)¶
Repaints the canvas map
- refreshAllLayers(self)¶
Reload all layers (including refreshing layer properties from their data sources), clears the cache and refreshes the canvas.
Note
Consider using the less expensive
redrawAllLayers()
method if a layer reload from the data provider is not required.New in version 2.9.
- removeInteractionBlocker(self, blocker: QgsMapCanvasInteractionBlocker)¶
Removes an interaction
blocker
from the canvas.See also
See also
New in version 3.14.
- Parameters:
blocker (QgsMapCanvasInteractionBlocker) –
- renderComplete¶
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
- renderErrorOccurred¶
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
- renderFlag(self) bool ¶
Returns
True
if canvas render is disabled as a result of user disabling renders via the GUI.See also
See also
have been halted programmatically, while
renderFlag()
should be used to determine whether a user has disabled rendering via GUI.- Return type:
bool
- renderStarting¶
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
- renderedItemResults(self, allowOutdatedResults: bool = True) QgsRenderedItemResults ¶
Gets access to the rendered item results (may be
None
), which includes the results of rendering annotation items in the canvas map.If the
allowOutdatedResults
flag isFalse
then outdated rendered item results (e.g. as a result of an ongoing canvas render) will not be returned, and insteadNone
will be returned.New in version 3.22.
- Parameters:
allowOutdatedResults (bool = True) –
- Return type:
- resizeEvent(self, e: QResizeEvent)¶
- Parameters:
e (QResizeEvent) –
- rotation(self) float ¶
Gets the current map canvas rotation in clockwise degrees
New in version 2.8.
- Return type:
float
- rotationChanged¶
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
- saveAsImage(self, fileName: str, QPixmap: QPixmap = None, a2: str = '')¶
Save the contents of the map canvas to disk as an image
- Parameters:
fileName (str) –
QPixmap (QPixmap = None) –
a2 (str = '') –
- scale(self) float ¶
Returns the last reported scale of the canvas. The
scale
value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.- Return type:
float
- scaleChanged¶
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
- scaleLockChanged¶
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
- scaleLocked(self) bool ¶
Returns whether the scale is locked, so zooming can be performed using magnication.
See also
New in version 2.16.
- Return type:
bool
- QgsMapCanvas.scrollContentsBy(self, int, int)
- selectionChanged¶
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
- selectionChangedSlot(self)¶
Receives signal about selection change, and pass it on with layer info
- selectionColor(self) QColor ¶
Returns color for selected features
New in version 3.0.
- Return type:
QColor
- sender(self) QObject ¶
- senderSignalIndex(self) int ¶
- setAnnotationsVisible(self, visible: bool)¶
Sets whether annotations are
visible
in the canvas.See also
New in version 3.0.
- Parameters:
visible (bool) –
- setCachingEnabled(self, enabled: bool)¶
Set whether to cache images of rendered layers
See also
See also
New in version 2.4.
- Parameters:
enabled (bool) –
- setCanvasColor(self, _newVal: QColor | Qt.GlobalColor | QGradient)¶
Write property of QColor bgColor.
- Parameters:
_newVal (Union[QColor) –
- setCenter(self, center: QgsPointXY)¶
Set the center of the map canvas, in geographical coordinates
New in version 2.8.
- Parameters:
center (QgsPointXY) –
- setCurrentLayer(self, layer: QgsMapLayer)¶
- Parameters:
layer (QgsMapLayer) –
- setDestinationCrs(self, crs: QgsCoordinateReferenceSystem)¶
Sets destination coordinate reference system
New in version 2.4.
- Parameters:
crs (QgsCoordinateReferenceSystem) –
- setExpressionContextScope(self, scope: QgsExpressionContextScope)¶
Sets an expression context scope for the map canvas. This scope is injected into the expression context used for rendering the map, and can be used to apply specific variable overrides for expression evaluation for the map canvas render. This method will overwrite the existing expression context scope for the canvas.
- Parameters:
scope (QgsExpressionContextScope) – new expression context scope
See also
See also
New in version 2.12.
- setExtent(self, r: QgsRectangle, magnified: bool = False)¶
Sets the extent of the map canvas to the specified rectangle.
The
magnified
argument dictates whether existing canvas constraints such as a scale lock should be respected or not during the operation. Ifmagnified
isTrue
then an existing scale lock constraint will be applied. This means that the final visible canvas extent may not match the specified extent.If
magnified
isFalse
then scale lock settings will be ignored, and the specified rectangle will ALWAYS be visible in the canvas.- Parameters:
r (QgsRectangle) –
magnified (bool = False) –
- setLabelingEngineSettings(self, settings: QgsLabelingEngineSettings)¶
Sets global labeling engine settings in the internal map settings
New in version 3.0.
- Parameters:
settings (QgsLabelingEngineSettings) –
- setLayerStyleOverrides(self, overrides: Dict[str, str])¶
Sets the stored overrides of styles for rendering layers.
If the map canvas has been associated with a map theme via a call to
setTheme()
, then any calls tosetLayerStyleOverrides()
are ignored. It is necessary to first clear the theme association by callingsetTheme()
with an empty string beforesetLayerStyleOverrides()
calls can be made.See also
New in version 2.12.
- Parameters:
overrides (Dict[str) –
- setLayers(self, layers: Iterable[QgsMapLayer])¶
Sets the list of
layers
that should be shown in the canvas.If the map canvas has been associated with a map theme via a call to
setTheme()
, then any calls tosetLayers()
are ignored. It is necessary to first clear the theme association by callingsetTheme()
with an empty string beforesetLayers()
calls can be made.See also
New in version 3.0.
- Parameters:
layers (Iterable[QgsMapLayer]) –
- setMagnificationFactor(self, factor: float, center: QgsPointXY = None)¶
Sets the factor of magnification to apply to the map canvas. Indeed, we increase/decrease the DPI of the map settings according to this factor in order to render marker point, labels, … bigger.
- Parameters:
factor (float) – The factor of magnification
center (
QgsPointXY
= None) – Optional point to re-center the map
New in version 2.16.
- setMapSettingsFlags(self, flags: Qgis.MapSettingsFlags | Qgis.MapSettingsFlag)¶
Resets the
flags
for the canvas’ map settings.New in version 3.0.
- Parameters:
flags (Union[Qgis.MapSettingsFlags) –
- setMapTool(self, mapTool: QgsMapTool, clean: bool = False)¶
Sets the map tool currently being used on the canvas
- Parameters:
mapTool (QgsMapTool) –
clean (bool = False) –
- setMapUpdateInterval(self, timeMilliseconds: int)¶
Set how often map preview should be updated while it is being rendered (in milliseconds)
New in version 2.4.
- Parameters:
timeMilliseconds (int) –
- setParallelRenderingEnabled(self, enabled: bool)¶
Set whether the layers are rendered in parallel or sequentially
New in version 2.4.
- Parameters:
enabled (bool) –
- setPreviewJobsEnabled(self, enabled: bool)¶
Sets whether canvas map preview jobs (low priority render jobs which render portions of the view just outside of the canvas extent, to allow preview of these out-of-canvas areas when panning or zooming out the map) are
enabled
for the canvas.See also
New in version 3.0.
- Parameters:
enabled (bool) –
- setPreviewMode(self, mode: QgsPreviewEffect.PreviewMode)¶
Sets a preview mode for the map canvas. This setting only has an effect if previewModeEnabled is
True
.- Parameters:
mode (QgsPreviewEffect.PreviewMode) – preview mode for the canvas
See also
See also
See also
New in version 2.3.
- setPreviewModeEnabled(self, previewEnabled: bool)¶
Enables a preview mode for the map canvas
- Parameters:
previewEnabled (bool) – set to
True
to enable a preview mode
See also
New in version 2.3.
- setProject(self, project: QgsProject)¶
Sets the
project
linked to this canvas.New in version 3.14.
- Parameters:
project (QgsProject) –
- setReferencedExtent(self, extent: QgsReferencedRectangle) bool ¶
Sets the canvas to the specified
extent
.- Return type:
bool
- Returns:
True
if the zoom was successful.- Raises:
QgsCsException – if a transformation error occurred.
New in version 3.10.
- Parameters:
extent (QgsReferencedRectangle) –
- setRenderFlag(self, flag: bool)¶
Sets whether a user has disabled canvas renders via the GUI.
- Parameters:
flag (bool) – set to
False
to indicate that user has disabled renders
See also
See also
freeze()
whilesetRenderFlag()
should only be used when users disable rendering via GUI.
- setRotation(self, degrees: float)¶
Set the rotation of the map canvas in clockwise degrees
New in version 2.8.
- Parameters:
degrees (float) –
- setScaleLocked(self, isLocked: bool)¶
Lock the scale, so zooming can be performed using magnication
See also
New in version 2.16.
- Parameters:
isLocked (bool) –
- setSegmentationTolerance(self, tolerance: float)¶
Sets the segmentation tolerance applied when rendering curved geometries
- Parameters:
tolerance (float) – the segmentation tolerance
- setSegmentationToleranceType(self, type: QgsAbstractGeometry.SegmentationToleranceType)¶
Sets segmentation tolerance type (maximum angle or maximum difference between curve and approximation)
- Parameters:
type (QgsAbstractGeometry.SegmentationToleranceType) – the segmentation tolerance typename
- setSelectionColor(self, color: QColor | Qt.GlobalColor | QGradient)¶
Set color of selected vector features
New in version 2.4.
- Parameters:
color (Union[QColor) –
- setSnappingUtils(self, utils: QgsSnappingUtils)¶
Assign an instance of snapping utils to the map canvas. The instance is not owned by the canvas, so it is possible to use one instance in multiple canvases.
For main canvas in QGIS, do not associate a different instance from the existing one (it is updated from the project’s snapping configuration).
New in version 2.8.
- Parameters:
utils (QgsSnappingUtils) –
- setTemporalController(self, controller: QgsTemporalController)¶
Sets the temporal
controller
for this canvas.The controller will be used to update the canvas’ temporal range.
New in version 3.14.
- Parameters:
controller (QgsTemporalController) –
- setTemporalRange(self, range: QgsDateTimeRange)¶
Set datetime
range
for the map canvas.The
temporalRangeChanged()
signal will be emitted if the temporal range has been changed.Note
Calling
setTemporalRange()
does not automatically trigger a map refresh.See also
New in version 3.14.
- Parameters:
range (QgsDateTimeRange) –
- setTheme(self, theme: str)¶
Sets a map
theme
to show in the canvas. The theme name must match a theme present in the associated project’sQgsMapThemeCollection
.When the canvas is associated to a map theme, it will automatically follow the layer selection and layer styles from that theme. Calls to
setLayers()
orsetLayerStyleOverrides()
will have no effect, and canvases associated with aQgsLayerTreeMapCanvasBridge
will no longer synchronize their state with the layer tree. In these cases it is necessary to callsetTheme()
with an empty string to clear the theme association and allow map updates withsetLayers()
,setLayerStyleOverrides()
, or viaQgsLayerTreeMapCanvasBridge
.If an empty string is passed then the current theme association will be cleared.
See also
New in version 3.0.
- Parameters:
theme (str) –
- setWheelFactor(self, factor: float)¶
Sets wheel zoom factor (should be greater than 1)
- Parameters:
factor (float) –
- setZRange(self, range: QgsDoubleRange)¶
Sets the
range
of z-values which will be visible in the map.See also
See also
New in version 3.18.
- Parameters:
range (QgsDoubleRange) –
- setZoomResolutions(self, resolutions: Iterable[float])¶
Set a list of resolutions (map units per pixel) to which to “snap to” when zooming the map
- Parameters:
resolutions (Iterable[float]) – A list of resolutions
New in version 3.12.
- setupViewport(self, QWidget)¶
- showEvent(self, event: QShowEvent)¶
- Parameters:
event (QShowEvent) –
- snappingUtils(self) QgsSnappingUtils ¶
Returns snapping utility class that is associated with map canvas. If no snapping utils instance has been associated previously, an internal will be created for convenience (so map tools do not need to test for existence of the instance).
Main canvas in QGIS returns an instance which is always up-to-date with the project’s snapping configuration.
New in version 2.8.
- Return type:
- stopRendering(self)¶
stop rendering (if there is any right now)
New in version 2.4.
- tabletEvent(self, QTabletEvent)¶
- tapAndHoldGestureOccurred¶
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
- temporalController(self) QgsTemporalController ¶
Gets access to the temporal controller that will be used to update the canvas temporal range.
New in version 3.14.
- Return type:
- temporalRange(self) QgsDateTimeRange ¶
Returns map canvas datetime range.
See also
New in version 3.14.
- Return type:
- temporalRangeChanged¶
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
- theme(self) str ¶
Returns the map’s theme shown in the canvas, if set.
See also
New in version 3.0.
- Return type:
str
- themeChanged¶
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
- timerEvent(self, QTimerEvent)¶
- transformContextChanged¶
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
- unsetMapTool(self, mapTool: QgsMapTool)¶
Unset the current map tool or last non zoom tool
This is called from destructor of map tools to make sure that this map tool won’t be used any more. You don’t have to call it manually,
QgsMapTool
takes care of it.- Parameters:
mapTool (QgsMapTool) –
- updateCanvasItemPositions(self)¶
called on resize or changed extent to notify canvas items to change their rectangle
- updateMicroFocus(self)¶
- updateScale(self)¶
Emits signal scaleChanged to update scale in main window
- viewportEvent(self, event: QEvent) bool ¶
- Parameters:
event (QEvent) –
- Return type:
bool
- viewportMargins(self) QMargins ¶
- viewportSizeHint(self) QSize ¶
- waitWhileRendering(self)¶
Blocks until the rendering job has finished.
In almost all cases you do NOT want to call this, as it will hang the UI until the rendering job is complete. It’s included in API solely for unit testing and standalone Python scripts.
New in version 3.0.
- wheelEvent(self, e: QWheelEvent)¶
- Parameters:
e (QWheelEvent) –
- writeProject(self, QDomDocument)¶
called to write map canvas settings to project
- xyCoordinates¶
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
- zRange(self) QgsDoubleRange ¶
Returns the range of z-values which will be visible in the map.
See also
See also
New in version 3.18.
- Return type:
- zRangeChanged¶
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
- zoomByFactor(self, scaleFactor: float, center: QgsPointXY = None, ignoreScaleLock: bool = False)¶
Zoom with the factor supplied. Factor > 1 zooms out, interval (0,1) zooms in If point is given, re-center on it.
If
ignoreScaleLock
is set toTrue
, then any existing constraint on the map scale of the canvas will be ignored during the zoom operation.- Parameters:
scaleFactor (float) –
center (
QgsPointXY
= None) –ignoreScaleLock (bool = False) –
- zoomIn(self)¶
Zoom in with fixed factor
- zoomInFactor(self) float ¶
Returns the zoom in factor.
- Return type:
float
- zoomLastStatusChanged¶
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
- zoomNextStatusChanged¶
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
- zoomOut(self)¶
Zoom out with fixed factor
- zoomOutFactor(self) float ¶
Returns the zoom in factor.
- Return type:
float
- zoomResolutions(self) List[float] ¶
- Return type:
List[float]
- Returns:
List of resolutions to which to “snap to” when zooming the map
See also
New in version 3.12.
- zoomScale(self, scale: float, ignoreScaleLock: bool = False)¶
Zooms the canvas to a specific
scale
. The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.If
ignoreScaleLock
is set toTrue
, then any existing constraint on the map scale of the canvas will be ignored during the zoom operation.- Parameters:
scale (float) –
ignoreScaleLock (bool = False) –
- zoomToFeatureExtent(self, rect: QgsRectangle)¶
Zooms to feature extent. Adds a small margin around the extent and does a pan if rect is empty (point extent)
- Parameters:
rect (QgsRectangle) –
- zoomToFeatureIds(self, layer: QgsVectorLayer, ids: object)¶
Set canvas extent to the bounding box of a set of features
- Parameters:
layer (QgsVectorLayer) – the vector layer
ids (object) – the feature ids
- zoomToFullExtent(self)¶
Zoom to the full extent of all layers currently visible in the canvas.
See also
- zoomToNextExtent(self)¶
Zoom to the next extent (view)
- zoomToPreviousExtent(self)¶
Zoom to the previous extent (view)
- zoomToProjectExtent(self)¶
Zoom to the full extent the project associated with this canvas.
This method zooms to the full extent for the project associated with this canvas. Unlike
zoomToFullExtent()
, this method does NOT consider which layers are actually visible in the map canvas.New in version 3.20.
- zoomToSelected(self, layer: QgsMapLayer = None)¶
Zoom to the extent of the selected features of provided map layer.
- Parameters:
layer (
QgsMapLayer
= None) – optionally specify different than current layer
zoomToSelected(self, layers: Iterable[QgsMapLayer]) Zoom to the combined extent of the selected features of all provided (vector) layers.
- Parameters:
layers – A list of layers
New in version 3.18.
- zoomWithCenter(self, x: int, y: int, zoomIn: bool)¶
Zooms in/out with a given center
- Parameters:
x (int) –
y (int) –
zoomIn (bool) –