Self.shape = "NONE" # Can set to "Line", "Circle" or "Rectangle" for interactive shape drawing and to activate the onLine/Polygon/Circle event sinks.ĭef onMouseDownMap(self, x, y, button, shift): """Implementation for MouseClickSample_addin.MCtool (Tool)""" The function 'onMouseDownMap' passes the map's coordinates to the add-in.Open the Python script that is generated for the add-in and find the tool class that was added in Step 1.Go through the wizard to create a new toolbar and a subsequent new tool. Install the Python Add-in Wizard and start a project.Click the 'ArcGIS Help 10.1 - What is a Python add-in?' link to get started. Refer to the Python Add-in Guide Book found in Related Information for information on making add-ins. Please note, using this feature requires familiarization with the use of the Python Add-ins Wizard. The instructions provided describe how to set up Python Add-in code to capture coordinates with a mouse click. Now Python Add-ins give users the ability to create Python written tools that respond to a mouse click. Prior to ArcGIS 10.1, Python could not be used to interact with the ArcGIS interface. # print("my position is:",self.xx,self.How To: Capture map coordinates with a mouse click using Python Summary # Mouse click event is used to process events after mouse click, including: # Mouse movement event, used to obtain accurate coordinates (as if the coordinates clicked by the mouse were inaccurate) # Start the timer and notify to refresh the data every 1 second # In this way, only the curve is re plot ted, and the performance is higher # The real-time display should obtain the PlotDataItem object and call its setData method, # Set the upper, lower, left and right label s All complete codes are as follows, which can be used directly after copying: # Capture mouse movement eventsįrom PySide2 import QtGui, QtWidgets, QtCore The above is all the ideas to solve my needs. # The parameter pos is a pixel coordinate, which needs to be converted into a scale coordinate # After capturing the click event, the actions to be done are completed in the mouseover function, mainly extracting the coordinates of the points The main codes of mouse movement are as follows: # Capture mouse movement events So in the whole program, I used two trigger events, one is mouse click and the other is mouse movement. After testing, the coordinates extracted by moving the mouse event are accurate. Normally, the return value of sigMouseClicked is an event, which contains the coordinates of the click time, but this coordinate is inaccurate, which is somewhat different from the actual position. # After capturing the click event, you need to do the action in mouse_ Completed in the clicked functionī) Get the coordinates corresponding to the graphic position when the mouse clicks. The main code is as follows: # Capture mouse click events In practice, I also divide this part into two steps: a) capture the mouse click signal. I haven't used pyqt before, so I don't know how to capture the mouse click signal, let alone extract the corresponding position coordinates. (self.updateData)ģ) Left click the drawing interface to add a new point. # Start the timer and notify to refresh the data every 100ms # Give the X and Y coordinates of points and draw a scatter diagramĢ) After the number of nodes or coordinates change, the position can be updated in real time. Self.scatter = .plot(pen=None, symbol='o') My requirements are mainly divided into the following parts: 1) Given the node coordinates, it can be displayed in the form of scatter diagram. I learned from the online code, combined with my own needs, and finally realized the functions I needed. After a search, I found that pyqt seemed to meet my needs, and I could find some relevant code. It feels that matplotlib completely depends on data-driven (that is, it can draw pictures by providing data), but it can not realize the two-way interaction between users and graphics (that is, users can generate new points by clicking with the mouse). However, it seems that it can not achieve the functions I need. In ordinary python drawing, my commonly used tool is matplotlib. In a recent project, the required function is to use the mouse to add nodes (the position where the mouse clicks is the node coordinates), and the point coordinates can be displayed visually and dynamically after being added. 1) Problem motivation and usage scenarios
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |