shudak

Problem Writing Attributes w/ UpdateCursor

Discussion created by shudak on Jan 9, 2013
Latest reply on Jan 9, 2013 by Caleb1987
Hello,

I have two feature classes with features snapped together. In one area I might have 3 points from feature class A, and 3 points snapped to those points 1:1 from feature class B. The points from A have several attributes that need to be written over to the points in B that are snapped to them. For those familiar with electric transmission I have support structures and guy wires (as points) and am testing using just the symbol rotation attribute.

I am writing a python script to facilitate this. These several attributes will go to fields with the same names in feature class B features. I am using the idea that where an INTERSECT occurs, I can select the attributes, store them in a list in sequence, then use the Update Cursor to write the list in sequence to the features in feature class B.

I am able to build my sequential list, but no matter how hard I try I cannot for the life of me get that list to populate the attributes in the other feature class. If anyone can look at my code and give me ideas or perhaps provide me a better way to do this, I would appreciate it. This operation is necessary for many thousands of points.

The code is as follows with some comments:

import arcpy

SSLayer = "C:\\............T_SUPPORTSTRUCTURE"
GuyLayer = "C:\\.............T_GUY"

SRlist = []

try:
    # Make a feature layer with Support Structures
    arcpy.MakeFeatureLayer_management(SSLayer, "AllSSLayer")

    # Make a feature layer containing only the Guy Wires Layer
    arcpy.MakeFeatureLayer_management(GuyLayer,"SelectionGuyLayer")

    # Apply a spatial selection of guy wires to the Support Structures layer
    arcpy.SelectLayerByLocation_management("AllSSLayer","INTERSECT","SelectionGuyLayer")

    # Open a search cursor on the Support Structures layer
    rows = arcpy.SearchCursor("AllSSLayer")
    row = rows.next()

    # Create a sequential list of the symbol rotation of all the selected support structures
    while row:
       SRlist.append(row.getValue("SYMBOLROTATION"))
       row = rows.next()

    # Clean up cursor and row objects
    del row
    del rows 
     
except:
    print arcpy.GetMessages()



try:

    # create an update cursor on the guy features
    rows = arcpy.UpdateCursor("GuyLayer", SYMBOLROTATION)
    while row:
        for row in rows:
            for i1, v1 in enumerate(SRlist):
                if row.SYMBOLROTATION == 0:     
                    row.SYMBOLROTATION = v1
                    rows.updateRow(row)
        row = rows.next()

    del row
    del rows 

except:
    print arcpy.GetMessages()

# Clean up feature layers
arcpy.Delete_management("AllSSLayer")
arcpy.Delete_management("SelectionGuyLayer")


Again, any help would be much appreciated.

Best,
SH

Outcomes