AnsweredAssumed Answered

insertrow with dictionary and list

Question asked by CCweedcontrol on Aug 13, 2015
Latest reply on Aug 14, 2015 by blake.terhune

i have a code that has two issues 1. only one point gets updated with the parcel attributes no other points get updated and 2. the  insertRow i currently have does not work it give me .

line 63, in <module>


TypeError: sequence size must match size of the row


basically i am trying to create multiple points that spatially joins the new created points to parcels and updates the points attributes based on what parcel the points are created i am not sure why i am getting the following error.


line 63, in <module>


TypeError: sequence size must match size of the row


I have checked to see if the "point" is being updated by the updatecursor with arcpy.FeatureClassToFeatureClass_conversion(point, "C:\Temp\Default.gdb", "p_lyr")  after updateRows.updateRow(updateRow)  and it looks like only one point gets updated.
Separate question, Can i use the SpatialJoin to "In_memory" instead of to a gdb?
I would really appreciate some help please.
working with.

#import modules

import arcpy

# Allow overwrite

arcpy.env.overwriteOutput = True

arcpy.env.qualifiedFieldNames = False

# Script user input parameters

pointFC = "CCA

parcel = "Parcels1" #Taxparcels

arcpy.env.workspace = r"C:\Temp\Default.gdb"

parcel_lyr = 'parcel_lyr'

sjpoints = "C:\Temp\Default.gdb\sjpoints"

poly = "ACCOUNT_1"

Pnt =  "Account"

mxd = arcpy.mapping.MapDocument("CURRENT")

df = arcpy.mapping.ListDataFrames(mxd)[0]

dfsr = df.spatialReference

fcsr = arcpy.Describe(pointFC).spatialReference

if ==

    """Now do your work"""

point = arcpy.GetParameterAsText(0)  #click

for prow in arcpy.da.SearchCursor(point,'SHAPE@XY'): 

        x,y = prow[0]

del prow

point1 = arcpy.Point(x, y) 

ptGeometry = arcpy.PointGeometry(point1)

insCursor = arcpy.da.InsertCursor(pointFC,'SHAPE@XY') # create insert cursor



#Run the Spatial Join tool, using the defaults for the join operation and join type

arcpy.SpatialJoin_analysis(point, parcel_lyr , sjpoints)

#arcpy.FeatureClassToFeatureClass_conversion(parcel_lyr, "C:\Temp\Default.gdb", "parcel_lyr")

# define the field list from the spatial join

sourceFieldsList = ["TARGET_FID", poly,"SiteAddress",'SiteNum_1', 'SiteStreet_1','SiteStreet_1','SiteNumSfx_1','Predir_1','Postdir_1', 'SiteCity_1', 'SiteZIP_1', 'OwnerName_1']

# define the field list to the original points

updateFieldsList = ["OID@", Pnt,"SiteAddres",'SiteNum','StreetName', 'SiteStreet', 'SiteNumSfx','Predir', 'Postdir', 'SiteCity', 'SiteZip', 'OwnerName']

# populate the dictionary from the polygon

valueDict = {r[0]:(r[1:]) for r in arcpy.da.SearchCursor(sjpoints, sourceFieldsList)}

with arcpy.da.UpdateCursor(point, 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]


            #arcpy.FeatureClassToFeatureClass_conversion(point, "C:\Temp\Default.gdb", "p_lyr")

            with arcpy.da.SearchCursor(point,('Account','SiteAddres','SiteNum','StreetName', 'SiteStreet', 'SiteNumSfx','Predir', 'Postdir', 'SiteCity', 'SiteZip', 'OwnerName')) as cursor: # loop through feature set

                for row in cursor:

                    row = []