import arcpy # Set the input workspace arcpy.env.workspace = arcpy.GetParameterAsText(0) # Set the output workspace outWorkspace = arcpy.GetParameterAsText(1) try: # Get a list of the featureclasses in the input folder fcs = arcpy.ListFeatureClasses() for fc in fcs: # Validate the new feature class name for the output workspace. featureClassName = arcpy.ValidateTableName(fc, outWorkspace) outFeatureClass = os.path.join(outWorkspace, featureClassName) # Set local variables inTable = arcpy.GetParameterAsText(2) fieldName1 = "symbol" expression = "Reclass(string(!MTFCC!))" codeblock = """def Reclass(symbol): if MTFCC == "H3010": return "River" elif MTFCC == "H1100": return "Creek"""" # Add fields arcpy.AddField_management(inTable, fieldName1, "STRING") # Calculate symbol values arcpy.CalculateField_management(inTable, fieldName1, expression, "PYTHON_9.3", codeblock) except: arcpy.AddMessage(arcpy.GetMessages(2)) print arcpy.GetMessages(2)
Okay, thanks for that input, Thanos. I have decided that an actual script within a toolbox is the route that I am going to go. I have this worked out so far:import arcpy # Set the input workspace # arcpy.env.workspace = arcpy.GetParameterAsText(0) # Set the output workspace # outWorkspace = arcpy.GetParameterAsText(1) try: # Get a list of the featureclasses in the input folder # fcs = arcpy.ListFeatureClasses() for fc in fcs: # Validate the new feature class name for the output workspace. # featureClassName = arcpy.ValidateTableName(fc, outWorkspace) outFeatureClass = os.path.join(outWorkspace, featureClassName) def Reclass(symbol): if MTFCC == "H3010": return "River" elif MTFCC == "H1100": return "Creek" except: arcpy.AddMessage(arcpy.GetMessages(2)) print arcpy.GetMessages(2)Basically I am to the point where I tell it what to do and I'm not really sure how to do so.
import arcpy # Set the input workspace # arcpy.env.workspace = arcpy.GetParameterAsText(0) # Set the output workspace # outWorkspace = arcpy.GetParameterAsText(1) try: # Get a list of the featureclasses in the input folder # fcs = arcpy.ListFeatureClasses() for fc in fcs: # Validate the new feature class name for the output workspace. # featureClassName = arcpy.ValidateTableName(fc, outWorkspace) outFeatureClass = os.path.join(outWorkspace, featureClassName) def Reclass(symbol): if MTFCC == "H3010": return "River" elif MTFCC == "H1100": return "Creek" except: arcpy.AddMessage(arcpy.GetMessages(2)) print arcpy.GetMessages(2)
def Reclass(FIELD1): if FIELD1 == "H3010": return "River" elif FIELD1 == "ABC": return "Something"
Hello,I am very new to Python scripting and I am trying to write one that will take values (they are always consistent), and based on their value enter a string into another field. I am working with data that is always coded the same (referenced below as field1, and I want to take those codes and automate a way to populate a different field based on those codes. I have been trying to play with this, but it hasn't worked so far:Expression:Reclass(!FIELD1!)Code block:def Reclass(FIELD1): if (FIELD1 == "H3010"): return "River"Ideally this is supposed to end up being an expression that the user can just load into the field calculator and it will grab the values from FIELD1 and place the desired values into FIELD2.
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.