Map tools should inherit from the QgsMapTool,Ĭlass or any derived class, and selected as active tools in the canvas using You can write your custom tools, to implement a custom behavior to actions connect ( populateContextMenu ) 9 canvas. connect ( lambda * args : 6 print ( f 'Action triggered at ' )) 7 8 canvas. addMenu ( 'My Menu' ) 4 action = subMenu. Selected layer on the newly created canvasġ # a slot to populate the context menu 2 def populateContextMenu ( menu : QMenu, event : QgsMapMouseEvent ): 3 subMenu = menu. To invoke the canvas window,Īdd the following lines to instantiate the MyWnd class. You can try the above code in the Python console editor. toolZoomOut ) 49 50 def pan ( self ): 51 self. toolZoomIn ) 46 47 def zoomOut ( self ): 48 self. pan () 43 44 def zoomIn ( self ): 45 self. actionPan ) 33 34 # create the map tools 35 self. actionPan = QAction ( "Pan", self ) 20 21 self. actionZoomOut = QAction ( "Zoom out", self ) 19 self. actionZoomIn = QAction ( "Zoom in", self ) 18 self. Map canvas is a widget like any other Qt widget, so using it is as simple asġ from qgis.gui import * 2 from import QAction, QMainWindow 3 from import Qt 4 5 class MyWnd ( QMainWindow ): 6 def _init_ ( self, layer ): 7 QMainWindow. Map tools - for interaction with the map canvas Map canvas items - additional items that can be displayed on the map canvas To summarize, the map canvas architecture consists of three concepts: Some more functionality to the basic QGraphicsItem objects. The canvas items are usually used to give visualįeedback for map tools, for example, when creating a new polygon, the map toolĬreates a rubber band canvas item that shows the current shape of the polygon.Īll map canvas items are subclasses of QgsMapCanvasItem which adds Typical map canvas items are rubber bands (used for measuring, vector editingĮtc.) or vertex markers. Besides this item which acts as a background, there may be more map canvas items. The QgsMapCanvas class also controls refreshing Rendered to an image (using the QgsMapRendererJob class) and that image isĭisplayed on the canvas. Whenever the map has been panned, zoomed in/out (or some other action that triggersĪ refresh), the map is rendered again within the current extent. If not, please read the overview of the framework. We will assume that you areįamiliar enough with Qt to understand the concepts of the graphics scene, viewĪnd items. Items are placed and user can interact with them. This framework generally provides a surface and a view where custom graphics The implementation is based on the Qt Graphics View framework. The map canvas is implemented with the QgsMapCanvas Tool active and the user can switch between the available tools. Similar to other graphics programs, there is always one There are tools for panning, zooming, identifying layers, measuring, vectorĮditing and others. The interaction is done through the use of map tools: The canvas always shows a part of the map defined by theĬurrent canvas extent. It shows the map composed from overlaid map layers and allows interaction with The Map canvas widget is probably the most important widget within QGIS because Select a feature using QgsMapToolIdentifyFeature Tasks - doing heavy work in the background Expressions, Filtering and Calculating Values QGIS Desktop User Guide/Manual (QGIS 3.28).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |