前言
- 介绍地图画布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软件中呈现如下图:
地图画布小组件QgsMapCanvasItem
Typical 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 map
- map canvas items — additional items that can be displayed on the map canvas
- map tools — for interaction with the map canvas