AnsweredAssumed Answered

Concatenating attributes

Question asked by skasprick on Apr 18, 2016
Latest reply on Apr 23, 2016 by Dan_Patterson


Within a chosen shapefile I have the prefix, Area, that needs to be joined to the user specified attribute, chosen as a dropdown from a column within the shapefile. which will become the suffix within a new field.  For example, if the user chooses 'gridcode', then the end result should be Area1, Area2, Area3, etc for each of the rows within the Zone attribute column.  I have tried to use the CalculateField_management and update cursor, but both gave me errors and since I am relatively new to python, I wanted some input to help me along.  Sorry for not inserting the information below in python.

 

Input_Shapefile = arcpy.GetParameterAsText(0)

 

ID = arcpy.GetParameterAsText(1)

 

# Process: Add Zone

arcpy.AddField_management(Input_Shapefile, "Zone", "TEXT", "20", "2", "20", "", "NULLABLE", "NON_REQUIRED", "")

 

# Process: Name Zones

arcpy.CalculateField_management(Input_Shapefile, "Zone", 'Area' + str(ID), "PYTHON", "")

 

# Tried to use update cursor, but it created the output as AreaGRIDCODE rather than the gridcode values

# with arcpy.da.UpdateCursor(Input_Shapefile, "Zone") as cursor:

#    for row in cursor:

#        row.setValue("Zone", 'Area' + str(ID))

#        cursor.updateRow(row)

# del cursor

 

# I found this option below in my searches as it appeared similar to my needs, but still no luck

# ZoneRows = arcpy.UpdateCursor(Input_Shapefile)

# Zones = ZoneRows.next()

# while Zones:

#    Zones.setValue('Zone', "Area" + str(ID))

#    ZoneRows.updateRow(Zones)

#    Zones = ZoneRows.next()

# del Zones, ZoneRows

Outcomes