5.1 地图画布MapCanvas及其相关类介绍

发布时间:2026/7/7 18:13:43
5.1 地图画布MapCanvas及其相关类介绍 前言介绍地图画布MapCanvas以及其相关类QgsMapcanvas 地图画布用于显示地图QgsMapTool 地图工具用于和MapCanvas交互QgsMapCanvasItem 用于显示在地图画布上的其他项目说明文章中的示例代码均来自开源项目pyqgis示例大全qgis_py_api_apps地图画布(QgsMapcanvas)首先看pyqgis cookbook文档关于Map canvas的描述The Map canvas widget is probably the most important widget within QGIS because it shows the map composed from overlaid map layers and allows interaction with the map and layers. The canvas always shows a part of the map defined by the current canvas extent. The interaction is done through the use of map tools: there are tools for panning, zooming, identifying layers, measuring, vector editing and others. Similar to other graphics programs, there is always one tool active and the user can switch between the available tools.地图画布Map canvas小部件可能是 QGIS 中最重要的部件因为它显示由叠加的地图图层组成的地图并允许用户与地图和图层进行交互。画布始终显示当前画布范围定义的地图的一部分。交互是通过使用地图工具来完成的有用于平移、缩放、识别图层、测量、矢量编辑等工具。与其他图形程序类似始终有一个工具处于活动状态并且用户可以在可用工具之间进行切换。The map canvas is implemented with the QgsMapCanvas class in the qgis.gui module. The implementation is based on the Qt Graphics View framework. This framework generally provides a surface and a view where custom graphics items are placed and user can interact with them. We will assume that you are familiar enough with Qt to understand the concepts of the graphics scene, view and items. If not, please read the overview of the framework.地图画布Map canvas在qgis.gui模块中通过QgsMapCanvas类实现。这个实现基于Qt的Graphics View框架。这个框架通常提供一个表面和一个视图其中可以放置自定义的图形项并且用户可以与它们进行交互。我们假设你对Qt有足够的了解能够理解图形场景、视图和项的概念。如果不是这样请阅读该框架的概述。QgsMapcanvas是qgis.gui模块中用于显示地图数据的类Map Canvas在QGis软件中呈现如下图地图工具(QgsMapTool)地图工具用于平移、缩放、识别图层、测量、矢量编辑等地图工具始终有一个工具处于活动状态并且用户可以在可用工具之间进行切换。Map Tool 在QGis软件中呈现如下图地图画布小组件QgsMapCanvasItemTypical map canvas items are rubber bands (used for measuring, vector editing etc.) or vertex markers. The canvas items are usually used to give visual feedback for map tools, for example, when creating a new polygon, the map tool creates a rubber band canvas item that shows the current shape of the polygon. All map canvas items are subclasses of QgsMapCanvasItem which adds some more functionality to the basic QGraphicsItem objects.典型的地图画布小组件包括橡皮筋(RubberBand)用于测量、矢量编辑等或顶点标记(Vertex Markers)。这些画布小组件通常用于为地图工具提供视觉反馈例如在创建新的多边形时地图工具会创建一个橡皮筋画布项来显示当前多边形的形状。所有地图画布项都是QgsMapCanvasItem的子类该类为基本的QGraphicsItem对象增加了更多功能。地图画布小组件在QGis软件中呈现如下图总结map canvas — for viewing of the mapmap canvas items — additional items that can be displayed on the map canvasmap tools — for interaction with the map canvas

相关新闻