AnsweredAssumed Answered

What's the best approach for updating the geometry of a point feature using the point geometry of a feature from a different feature class? I've been trying to use an Update Cursor to do this.

Question asked by Beibhin91941 on Nov 19, 2018
Latest reply on Nov 19, 2018 by jborgion

What's the best approach for updating the geometry of a point features (which start out as null) using the point geometry of a feature from a different feature class? I've been trying to use an Update Cursor to do this. I know how to get it to update a regular attribute, but not a geometry. And in my testing, it's looking like this may not be workable. I keep getting "TypeError: 'tuple' object does not support item assignment" which I find odd because when I check the type, it's "float".

 

Update: Okay, based on what Adrian pointed out, I changed the iterator in the inner, Search Cursor loop to "row2" and it now works fine. Silly me, I had been thinking "row" was a reserved word:) 

I've pasted my new code below. Thank you all - and I'll try to always post correctly formatted code in the future.  

import arcpy, datetime

arcpy.env.workspace = r'Database Connections\dev-sde.sde'  # type: str
ws = arcpy.env.workspace
# Start an edit session
edit = arcpy.da.Editor(ws)

edit.startEditing(False, True) # Change second parameter to True for versioned data
edit.startOperation()

fcs = (r"dev.sde.wControlValve",r"dev.sde.wSystemValve",r"dev.sde.wFitting")
dt = datetime.datetime.strptime("01/01/1970", "%d/%m/%Y")
fd = r"dev.sde.WaterDistribution"  # type: str

outer_cnt= 0
inner_cnt = 0
cnt_not_found = 0
with arcpy.da.UpdateCursor("{0}\{1}".format(fd,r"dev.sde.wPump"),[r"project",r"SHAPE@XY"]) as ucursor:
    for row in ucursor:
        print(row[0], row[1])
        print(type(row[0]))
        print(type(row[1]))
        src_prj = row[0]
        found = "false"
        print(src_prj)
        x = 0.0
        y = 0.0
        for fc in fcs: #Start searching through features in the point feature classes for feature with same project #
            print(fc)
            with arcpy.da.SearchCursor(("{0}\{1}".format(fd, fc)), [r"project", r"SHAPE@XY"]) as icursor:
                for row2 in icursor:
                    if row2[0]==src_prj:
                        #new_geom = row[1]
                        (x,y) = row2[1]
                        #print(type(new_geom))
                        #print(new_geom)
                        found = "true"
                        break
            if found == "true":
                print(found)
                break #Don't need to search in any further feature classes
        if found == "true":
            print(type(row[1]))
            row[1] = (x,y)
            ucursor.updateRow(row)
        else:
            cnt_not_found+=1

# Stop Edit Session
edit.stopOperation()
edit.stopEditing(True)
print(str(cnt_not_found)+ " project #s were not found in the listed feature classes")

del icursor
del ucursor

 

Outcomes