AnsweredAssumed Answered

Trying to add rows and update values using arcpy.da.InsertCursor

Question asked by lbrannon on Nov 4, 2013
Latest reply on Nov 5, 2013 by lbrannon
In my code, I am creating duplicate polygons from existing polygons all within the same feature class.  I am passing all the attributes from the original polygon to the duplicate.  This works fine.

But what I cannot figure out is how to change one attribute value in the duplicate polygon while using the InsertCursor object that creates the duplicate polygon.  If I could get the InsertCursor object to do it (update the one attribute value) while inside the same For loop where the duplicate polygon is created - using inCur.insertRow(rowParcel), then it would make it very easy for me to assign the correct value to the duplicate polygon.  In the code below, the fsa variable has the value that needs to be inserted into the duplicate polygon.

import arcpy  # Set Geoprocessing environments arcpy.env.scratchWorkspace = "F:\\ArcGISServer\\DataProcessing\\Mobile_Parcels\\TestData\\Testing.gdb" arcpy.env.workspace = "F:\\ArcGISServer\\DataProcessing\\Mobile_Parcels\\TestData\\Testing.gdb" arcpy.env.overwriteOutput = True   # Add code to generate target address list (dataset) addrList_fc = "F:\\ArcGISServer\\DataProcessing\\Mobile_Parcels\\TestData\\Testing.gdb\\addresspts_LeftOut_tmpSel"  # Loop through the address list dataset created above; check for parcel# match against target parcels dataset from earlier script; # create duplicate parcel & populate FULL_ADD targetParcels = "F:\\ArcGISServer\\DataProcessing\\Mobile_Parcels\\TestData\\Testing.gdb\\target_parcels_sample"  cursor2 = arcpy.da.SearchCursor(targetParcels, ["ASSESSORSI", "*", "SHAPE@"])  ## Maybe use ["ASSESSORSI", "FULL_ADD", "*"] inCur = arcpy.da.InsertCursor(targetParcels, ["ASSESSORSI", "*", "SHAPE@"])  # Loop thru the address dataset with arcpy.da.SearchCursor(addrList_fc, ["PARCELNO", "FSA"]) as cursor1:       for rowAddr in cursor1:         # Grab the address value from address dataset         fsa = rowAddr[1]         cursor2.reset()         # Loop thru the parcel dataset         for rowParcel in cursor2:             if rowAddr[0] == rowParcel[0]:  # Compare parcel # values for a match                 # If there is a match, use current parcel record to create a duplicate parcel and insert the current address value                 # into the parcels FULL_ADD field (don't know how to accomplish this last part)                 inCur.insertRow(rowParcel)                 break  # and get out of inner For Loop and proceed back to outer For Loop             #else, continue with the next row in the inner For Loop        del cursor1, cursor2, inCur, rowParcel, rowAddr print "Script completed"


Thanks in advance for any help.
Lee

Outcomes