I have a feature Class with the columns KOMMUNE and GKR and some other columns.. Both columns are string. In the column KOMMUNE I have the value 0723 and 0724. In column GKR I have the value 0107 and 0108. My problem is: If column KOMMUNE has the value 0723 i will add 2000 to the value 0107 in the colum GKR so the value becomes 2107 and if the value in KOMMUNE is 0724 I will add 3000 to the value 0108 in the colum GKR so the value becomes 3108.
Have tried with arcpy.CalculateField_management but I can not select the values with it.
import sys, string, os, arcpy
from arcpy import env
env.workspace = r"C:\Tom\ArcPyTest\Slå sammen kommuner"
#Kommune_1 = arcpy.GetParameterAsText(0)
#Kommune_2 = arcpy.GetParameterAsText(1)
#Nytt_Kommune_Nr = arcpy.GetParameterAsText(2)
Kommune_1 = 723
Kommune_2 = 720
Nytt_Kommune_Nr = "0722"
FcKommune = r"C:\Tom\ArcPyTest\Slå sammen kommuner\07_Vestfold inn.gdb\gkr2013_brutto07"
arcpy.env.overwriteOutput = True
arcpy.AddField_management(FcKommune, "KOM", "TEXT", '', '', 4)
arcpy.AddField_management(FcKommune, "GKR", "TEXT", '', '', 4)
arcpy.AddField_management(FcKommune, "KOMMUNE", "TEXT", '', '', 4)
arcpy.CalculateField_management(FcKommune, "KOMMUNE", "!" + "KOMM" + "!", "PYTHON")
rows = arcpy.da.UpdateCursor(FcKommune, ["KOMMUNE", "GRUNNKRETS", "KOM", "GKR"])
for row in rows:
if (row[0]) == str(Kommune_1):
row[2] = str(Nytt_Kommune_Nr)
if (row[0]) == str(Kommune_1):
row[3] = (row[1] [4:8])
if (row[0]) == str(Kommune_2):
row[2] = str(Nytt_Kommune_Nr)
if (row[0]) == str(Kommune_2):
row[3] = (row[1] [4:8])
if (row[0]) == str(Kommune_1):
arcpy.CalculateField_management(FcKommune, "GKR", "[GKR] +2000" , "VB", "")
if (row[0]) == str(Kommune_2):
arcpy.CalculateField_management(FcKommune, "GKR", "[GKR] +3000" , "VB", "")
rows.updateRow(row)