Tonyalmeida

Update fields from Spatial Join

Discussion created by Tonyalmeida on Apr 9, 2014
Latest reply on Apr 10, 2014 by Tonyalmeida
I am trying to populate some fields of a feature class from a spatial join. The fields i need have different names and i am not sure how to update those fields. I would appreciate any help.

For example i need to populate Fc field SiteStreet with the spatial join (fcOutpu) StreetName field and
Fc field SiteSubNum with the spatial join (fcOutpu) SubNum field.

I believe my problem is on this line
row.setValue(Field5, row.getValue(curR.SiteStreet))

gives me
'Cursor' object has no attribute 'SiteStreet



my current code
# do not need this scratch file
fcOutput = r'temp_join' #'temp_join' when using workspace = r"C:\Temp\default.gdb"
arcpy.SpatialJoin_analysis("in_memory\Par", "in_memory\point layer", fcOutput, 'JOIN_ONE_TO_MANY')

# grab oid field from points
oid_t = arcpy.Describe(fc).OIDFieldName

# init rowW and rowR
curR = arcpy.SearchCursor(fcOutput)
join_dict = dict([(r.JOIN_FID,[r.getValue(f) for f in add_fields]) for r in curR])
#del curR

Field5 = "StreetName"
Field6 = "SiteSubNum"

# Now update the new target
curW = arcpy.UpdateCursor(fc)
for row in curW:
    t_oid = row.getValue(oid_t)
    if t_oid in join_dict:
        for f in add_fields:
            row.setValue(f, join_dict[t_oid][add_fields.index(f)])
            row.setValue(Field, Text)
            row.setValue(Field1, Text1)
            row.setValue(Field2, Text2)
            row.setValue(Field3, datetime.datetime.now().strftime('%m/%d/%Y'))
            row.setValue(Field5, row.getValue(curR.SiteStreet))
            row.setValue(Field6, row.getValue(curR.SubNum))
        #else:
            #row.StreetName = curR.SiteStreet
    curW.updateRow(row)
del row, curW

Outcomes