How to calculate area with a python tool addin?

المشرف العام

Administrator
طاقم الإدارة
I know very little about programming. I am in the process of replacing an old VBA tool that calculates the drainage area of a selected polygon with a python tool. I am using the python addin wizard and have no idea what these parameters mean and how to make them do what I want them to do.

Basically I want a user to click on a button which allows them to interact with the map by selecting a polygon by clicking the vertices and double clicking to close the polygon. Upon closing I want the tool to display the area in hectares and further still, to calculate the drainage information for the area.

The VBA script is as follows:

Private Sub UIToolControl1_MouseDown(ByVal button As Long, ByVal shift As Long, ByVal x As Long, ByVal y As Long) Dim pRubberPolygon As IRubberBand Dim pPolygon As IPolygon Dim pPoint As IPoint Dim pEnvelope As IEnvelope

'Delete all elements to start with a clean mapCall DeleteElements'Get polygon shape from user (single mouse clicks add vertex and double mouse click finishes polygon)Set pRubberPolygon = New RubberPolygonSet pPolygon = pRubberPolygon.TrackNew(pScreenDisplay, pSFsymbol)If Not pPolygon Is Nothing Then 'Use the upper left extent of the polygon to place the text label Set pPoint = New Point Set pEnvelope = New Envelope pPolygon.QueryEnvelope pEnvelope Set pPoint = pEnvelope.UpperLeft 'Determine the area of the polygon, flow rate and crossing size Call CalcCrossingSize(pPolygon) 'Draw the polygon and label on the screen Call CreateTextElement(strLine, pPoint) Call DrawGeometry(pPolygon) Set pPoint = Nothing Set pEnvelope = NothingEnd IfSet pPolygon = NothingstrLine = ""End Sub

Sub CalcCrossingSize(pPolygon As IPolygon) 'Get the area of the polygon Dim pPolyArea As IArea Dim pPolyAreaNum As Double Dim pPolyFlowRate As Double Dim pPolyGeom As IGeometry

Set pPolyGeom = pPolygonSet pPolyArea = pPolyGeompPolyAreaNum = Abs(pPolyArea.Area) / 10000pPolyFlowRate = (pPolyAreaNum / 100) * 1.39'Determine minimum required pipe size depending upon pipe construction materialDim strCorrugated As StringIf pPolyAreaNum 68 And pPolyAreaNum 72 And pPolyAreaNum 95 And pPolyAreaNum 126 And pPolyAreaNum 201 And pPolyAreaNum 291 And pPolyAreaNum 353 And pPolyAreaNum 403 And pPolyAreaNum 550 And pPolyAreaNum 705 And pPolyAreaNum 899 And pPolyAreaNum = 1115 Then strCorrugated = "- Minimum corrugated pipe size is subject to ENV review."End IfNow the python addin wizard generates the following for the tool, does anyone know enough python and VBA to convert this? Will this even work in a python addin tool?

class ToolClass3(object): """Implementation for Test Addin_addin.tool (Tool)""" def init(self): self.enabled = True self.shape = "NONE" # 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): pass def onMouseUp(self, x, y, button, shift): pass def onMouseUpMap(self, x, y, button, shift): pass 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): pass def onRectangle(self, rectangle_geometry): pass



أكثر...
 
أعلى