I have created a model in ArcGIS ModelBuilder and in a point of the process I insert a python tool (New Field) to create new field in a shapefile.
After that I want to use this new field in other tool in the same model. But I cannot use it because it is not created, it is not selectable in the available fields of the shapefile.
This image shows a part of the model where I create the new field and after I want to use this new field as a input in Pivot Table tool.
The New Field toll python code is:
def getParameterInfo(self):
"""Define parameter definitions"""
# First parameter
param0 = arcpy.Parameter(
displayName="Shape entrada",
name="in_features",
datatype="GPTableView",
parameterType="Required",
direction="Input")
parameters = [param0]
return parameters
def isLicensed(self):
"""Set whether tool is licensed to execute."""
return True
def updateParameters(self, parameters):return
def updateMessages(self, parameters):return
def execute(self, parameters, messages):
"""The source code of the tool."""
#-----------------------------
camp= "GROUP_"
val= "Pix_Value"
a= parameters[0].valueAsText
arcpy.AddField_management(a, camp, "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(a, val, "SHORT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
#-----------------------------
with arcpy.da.UpdateCursor(a, ["CODE2012",camp, val]) as cursor:
for row in cursor:
a= int(row[0])
if a < 12100:
row[1] = "Residential"
row[2]= 5
elif a==12100 or a==12300 or a==12400:
row[1] = "Industrial"
row[2]= 4
elif a>12100 and a<12300:
row[1] = "Highway"
row[2]= 6
elif a == 21000:
row[1] = "AnnualCrop"
row[2]= 1
elif a == 22000 or a== 25000:
row[1] = "PermanentCrop"
row[2]=2
elif a == 23000:
row[1] = "Pasture"
row[2]=3
elif a == 31000:
row[1] = "Forest"
row[2]=8
elif a == 32000:
row[1] = "HerbaceousVegetation"
row[2]=9
elif a == 50000:
row[1] = "Water"
row[2]=7
else:
row[1]= "No_clasified"
row[2]=0
cursor.updateRow(row)
del a
del cursor`
