1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85 | # -*- coding: utf-8 -*-
import arcpy, sys, os
from arcpy import management as DM
class Toolbox(object):
def __init__(self):
"""Define the toolbox (the name of the toolbox is the name of the
.pyt file)."""
self.label = "heth"
self.alias = ""
# List of tool classes associated with this toolbox
self.tools = [heth]
class heth(object):
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "HETH"
self.description = ""
self.canRunInBackground = False
def getParameterInfo(self):
"""Define parameter definitions"""
intable = arcpy.Parameter(
displayName = "Input Table",
name = "intable",
datatype = "Table",
parameterType = "Required",
direction = "Input")
eastWest = arcpy.Parameter(
displayName = "eastWest",
name = "eastWest",
datatype = "Feature Layer",
parameterType = "Required",
direction = "Output")
northSouth = arcpy.Parameter(
displayName = "northSouth",
name = "northSouth",
datatype = "Feature Layer",
parameterType = "Required",
direction = "Output")
params = [intable,eastWest,northSouth]
return params
def isLicensed(self):
"""Set whether tool is licensed to execute."""
return True
def updateParameters(self, parameters):
"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parameter
has been changed."""
return
def updateMessages(self, parameters):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
return
def execute(self, parameters, messages):
infeatures = parameters[0].valueAsText
eastWest = parameters[1].valueAsText
northSouth = parameters[2].valueAsText
ws = os.path.dirname(sys.argv[0])
arcpy.env.workspace = ws
csv = r"memory\csv"
DM.CopyRows(infeatures, csv)
DM.AddField(csv, field_name="sd_w", field_type="float")
DM.AddField(csv, field_name="sd_e", field_type="float")
DM.AddField(csv, field_name="sd_n", field_type="float")
DM.AddField(csv, field_name="sd_s", field_type="float")
DM.CalculateField(csv, field="sd_w", expression="float(!mean_lon!) - float(!sd_lon!)")
DM.CalculateField(csv, field="sd_e", expression="float(!mean_lon!) + float(!sd_lon!)")
DM.CalculateField(csv, field="sd_n", expression="float(!sd_lat_!) + float(!mean_lat!)")
DM.CalculateField(csv, field="sd_s", expression="float(!mean_lat!) - float(!sd_lat_!)")
DM.XYToLine(csv, eastWest, startx_field="sd_w", starty_field="mean_lat", endx_field="sd_e", endy_field="mean_lat")
DM.XYToLine(csv, northSouth, startx_field="mean_lon", starty_field="sd_n", endx_field="mean_lon", endy_field="sd_s")
return
|