-
Notifications
You must be signed in to change notification settings - Fork 0
/
Toolbox.pyt
128 lines (106 loc) · 3.93 KB
/
Toolbox.pyt
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import arcpy
import scipy.stats
class Toolbox(object):
def __init__(self):
self.label = "myToolbox"
self.alias = ""
# List of tool classes associated with this toolbox
self.tools = [Winsorize]
class Winsorize(object):
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "Winsorize"
self.description = ""
self.canRunInBackground = True
def getParameterInfo(self):
"""Define parameter definitions"""
entrada = arcpy.Parameter(
displayName="Entrada",
name="entrada",
datatype="Feature Layer",
parameterType="Required",
direction="Input")
# Sinuosity Field parameter
winsorize_field = arcpy.Parameter(
displayName="Winsorize Field",
name="winsorize_field",
datatype="Field",
parameterType="Required",
direction="Input")
# winsorize_field.value = "winsorize"
# winsorize_field.columns = [['Field', 'Fields'], ['Long', 'Ranks']]
# # Derived Output Features parameter
# out_features = arcpy.Parameter(
# displayName="Salida",
# name="salida",
# datatype="Field",
# parameterType="Derived",
# direction="Output")
percentil = arcpy.Parameter(
displayName="Percentil",
name="percentil",
datatype="Long",
parameterType="Required",
direction="Input")
# winsorize_field.parameterDependencies = [winsorize_field.name]
winsorize_field.parameterDependencies = [entrada.name]
# arcpy.AddField_management(entrada, "nuevoCampo", "LONG", 9, "", "", "refcode", "NULLABLE", "REQUIRED")
parameters = [entrada,winsorize_field,percentil]
return parameters
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):
tabla = parameters[0].valueAsText
campo = parameters[1].valueAsText
percentil_entero = parameters[2].valueAsText
percentil = float(percentil_entero)/100
mylist = [(0.0)]
i=0
index=0
rows = arcpy.SearchCursor(tabla)
row = rows.next()
while row:
mylist.insert(index,row.getValue(campo))
index=index+1
row = rows.next()
resultado = scipy.stats.mstats.winsorize(mylist, limits=percentil)
fieldList = arcpy.ListFields(tabla)
fieldName = [f.name for f in fieldList]
field = "Winsor"
if field in fieldName:
arcpy.AddError("La columna WINSOR ya existe.".format(input))
raise arcpy.ExecuteError
else:
arcpy.AddField_management(tabla, field, "TEXT")
cursor = arcpy.UpdateCursor(tabla)
row = cursor.next()
while row:
# field2 will be equal to field1 multiplied by 3.0
row.setValue(field, resultado[i])
cursor.updateRow(row)
row = cursor.next()
i=i+1
del row
del rows
del cursor
# mylist = [(0.0)]
# index=0
# row = rows.next()
# while row:
# # print row.size
# # #value_table.addRow(row)
# mylist.insert(index,row)
# index=index+1
# row = rows.next()
# print len(mylist)
return