Select to view content in your preferred language

Update fields from Spatial Join

2580
4
04-09-2014 07:19 AM
TonyAlmeida
MVP Regular Contributor
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
Tags (2)
0 Kudos
4 Replies
JamesCrandall
MVP Alum
Just a quick idea:  make sure you are fully qualifying the field names appropriately.  They are altered after the join and may not be correctly naming the field(s).  A simple suggestion is to run the join manually in ArcGIS and then look at the field properties to see the correct full name(s).

Edit: I don't think this matters as it relates to Spatial Joins (I missed that in your OP).  Sorry for any confusion.
0 Kudos
TonyAlmeida
MVP Regular Contributor
jamesfreddyc thank you for the reply.
That was my first thought so i changed the fcOuput to C:/temp/default.gdb to make sure i had the correct fields and I do.
I believe the syntax to populate fc field from fcOuput is incorrect.
0 Kudos
AhmedEl-Sisi
Deactivated User
To get the value form your row you should pass the column name row.getValue("FieldName"), in your code you get the column name from the Cursor "cur.SiteStreet" which is incorrect syntax.
Try the following:
field = "SiteStreet"
row.getValue(field)
0 Kudos
TonyAlmeida
MVP Regular Contributor
cc4ever i have tried your suggestion and it populates the field with "SiteStreet" not what text is actually in the field.
I am lost on what is the correct syntax.
0 Kudos