AnsweredAssumed Answered

Invalid column value with arcpy.da.UpdateCursor

Question asked by CCweedcontrol on Dec 18, 2015
Latest reply on Jan 8, 2016 by chad.stidham

I have the following code and i am getting an error on line 76 with the arcpy.da.UpdateCursor that update feature attributes to proper case . I am unsure why. I would really appreciate some help please?




# Import arcpy module
import arcpy
from arcpy import env

# Allow overwrite 
arcpy.env.overwriteOutput = True

# Script user input parameters
polygonLayer = "DSD.DBO.TaxParcels1" #Taxparcels
pointLayer = "CCAPTEST.DBO.CCAP8" #Point Layer
arcpy.env.workspace = r"Database Servers\DSD15_SQLEXPRESS.gds\CCAPTEST (VERSION:dbo.DEFAULT)" #arcpy.env.workspace = r"Database Servers\DSD15_SQLEXPRESS.gds\TEST (VERSION:dbo.DEFAULT)"
poly = "ACCOUNT_1" 
Pnt =  "Account"
sjpoints = "In_memory\sjpoints" 

parcelsCount = int(arcpy.GetCount_management(pointLayer).getOutput(0))     
dsc = arcpy.Describe(pointLayer) 

selection_set = dsc.FIDSet         
if len(selection_set) == 0:       
    print "There are no features selected"  
elif parcelsCount >= 1: 

    #Run the Spatial Join tool, using the defaults for the join operation and join type
    arcpy.SpatialJoin_analysis(pointLayer, polygonLayer, sjpoints)

    # define the field list from the spatial join
    sourceFieldsList = ["TARGET_FID", poly,"SiteAddress",'SiteNum_1', 'SiteStreet_1','SiteNumSfx_1','Predir_1','SiteStreet_1','Postdir_1', 'SiteCity_1', 'SiteZIP_1', 'OwnerName_1', 'StreetType_1']    #,'StreetType_1'

    # define the field list to the original points
    updateFieldsList = ["OID@", Pnt,"SiteAddres", 'SiteNum', 'StreetName','SiteNumSfx','Predir','SiteStreet', 'Postdir', 'SiteCity', 'SiteZip', 'OwnerName', 'StreetType'] #, 'StreetType'
    # Start an edit session. Must provide the workspace.    
    edit = arcpy.da.Editor(arcpy.env.workspace)    
    # Edit session is started without an undo/redo stack for versioned data    
    #  (for second argument, use False for unversioned data)    
    # Start an edit operation    
    manualFields =  ["FacltyType","GIS_STEW", "StructType", "Verified", "Status", "StructCat", "APA_CODE",'StreetName'] #,'StreetName'
    with arcpy.da.UpdateCursor(pointLayer, manualFields) as rows:       
        for row in rows:       
            row[0] = ("Single Family Home")
            row[1] = ("Canyon")
            row[2] = ("Primary, Private")           
            row[3] = ("Yes, GRM, TA")           
            row[4] = ("Active")           
            row[5] = ("Residential")           
            row[6] = ("1110")
            row[7] = (sourceFieldsList[4] + " " + sourceFieldsList[12])
        del row       
        del rows 
    # populate the dictionary from the polygon
    valueDict = {r[0]:(r[1:]) for r in arcpy.da.SearchCursor(sjpoints, sourceFieldsList)}    

    with arcpy.da.UpdateCursor(pointLayer, updateFieldsList) as updateRows:    
        for updateRow in updateRows:    
            keyValue = updateRow[0]
            if keyValue in valueDict:    
                for n in range (1,len(sourceFieldsList)):      
                    updateRow[n] = valueDict[keyValue][n-1]
        del updateRows
        del updateRow

    #Update feature attributes to proper case
    fields1 = ["StreetName", "SiteStreet","SiteAddres","OwnerName","StreetType"]#,'StreetType'
    with arcpy.da.UpdateCursor(pointLayer, fields1) as cursor:
        for row in cursor:
            row[0] = row[0].title()
            row[1] = row[1].title()
            row[2] = row[2].title()
            row[3] = row[3].title()
            row[4] = row[4].title()
    # Stop the edit operation.    
    # Stop the edit session and save the changes