Geographic Information Systems Asked on April 24, 2021
I want to make a Python script that will calculate the distance of the line I drew and output it in a special form, but I can’t figure out what I’m doing wrong.
import arcpy
import pythonaddins
class ToolClass2(object):
"""Implementation for probn_addin.tool (Tool)"""
def __init__(self):
self.enabled = True
self.shape = "Line" # Can set to "Line", "Circle" or "Rectangle" for interactive shape drawing and to activate the onLine/Polygon/Circle event sinks.
def onMouseDown(self, x, y, button, shift):
pass
def onMouseDownMap(self, x, y, button, shift):
print(x,y)
return(x,y)
def onMouseUp(self, x, y, button, shift):
pass
def onMouseUpMap(self, x, y, button, shift):
print(x,y)
return(x,y)
def onMouseMove(self, x, y, button, shift):
pass
def onMouseMoveMap(self, x, y, button, shift):
pass
def onDblClick(self):
pass
def onKeyDown(self, keycode, shift):
pass
def onKeyUp(self, keycode, shift):
pass
def deactivate(self):
pass
def onCircle(self, circle_geometry):
pass
def onLine(self, line_geometry):
onMouseDownMap(x1,y1)
onMouseUpMap(x2,y2)
dist = math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
message = "Your lenght:" + str(dist)
pythonaddins.MessageBox(message, "Ruler")
def onRectangle(self, rectangle_geometry):
pass
Try replacing the following lines of code:
def onLine(self, line_geometry):
#onMouseDownMap(x1,y1)
#onMouseUpMap(x2,y2)
#dist = math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
message = "Your length: " + str(line_geometry.length)
pythonaddins.MessageBox(message, "Ruler",0)
This will return the length of the line which may have more than two vertices, your code would have returned the straight line distance between the end vertices, if it was working.
Answered by Hornbydd on April 24, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP