I need to generate a polygon FC using some records previously flagged as 'NUMBER_GT_NUMBER_END = 1'
These records need to be loaded into a new schema of the same FC in order to include duplicates that will be used later for other processes. If you run the code as I am giving it here, it will print out the number of records per OBJECTID. The issue is that I am able to insert only one for each case. Once added a record into the new FC schema, I want to update the SITUS_STREET_NUMBER field with the value stored in x + 1. I have been going back and forth with other approaches like using Append, Copy, among others, but the process is really slow in comparison to the one achieved so far using the da.cursors.
OBJECTID = 28964 ---> 3 records
This means that the above polygon geometry with OBJECTID = 28964 needs to be inserted to the new FC three times and that the SITUS_STREET_NUMBER field needs to be updated with the listed values.
import arcpy, re arcpy.env.workspace = r'YOUR DIRECTOTY PATH HERE\locator_address_ranges.gdb' arcpy.env.overwriteOutput = True # Set a variable for the workspace workspace = arcpy.env.workspace featureClass = workspace + '\\' + 'ParcelsTax_Formated' featureClassCopy = workspace + '\\' + 'ParcelsTax_Formated_new' number_Field = "SITUS_STREET_NUMBER" number_end_Field = "SITUS_STREET_NUMBER_END" oid = "OBJECTID" number_Field2 = "SITUS_STREET_NUMBER2" # Long Integer number_end_Field2 = "SITUS_STREET_NUMBER_END2" # Long Integer countAddrPnts = "Points" # Long Integer full_addr = "SITUS_FULL_ADDRESS" greater_than = "NUMBER_GT_NUMBER_END" # Value = 1 --> SITUS_STREET_NUMBER2 is > than SITUS_STREET_NUMBER_END2 - Short Integer fieldsToUpdate = (number_Field, full_addr) dsc = arcpy.Describe(featureClass) fields = dsc.fields # List all field names except the OID field fieldnames = [field.name for field in fields] fieldnames.append("SHAPE@") print "Updated List : ", fieldnames ## STEP 1 # Insert rows for scenario where SITUS_STREET_NUMBER2 is > than SITUS_STREET_NUMBER_END2 arcpy.MakeFeatureLayer_management(featureClass, "countAddrPnts_lyr") arcpy.SelectLayerByAttribute_management("countAddrPnts_lyr", "NEW_SELECTION", 'NUMBER_GT_NUMBER_END = 1') rows = arcpy.SearchCursor(featureClass, 'NUMBER_GT_NUMBER_END = 1') row = rows.next() while row: arcpy.SelectLayerByAttribute_management("countAddrPnts_lyr", "NEW_SELECTION", "OBJECTID = " + str(row.getValue(oid))) print "OBJECTID = " + str(row.getValue(oid)) + ' ---> ' + str(row.getValue(countAddrPnts) + 1) + ' records' with arcpy.da.SearchCursor(featureClass, fieldnames, 'NUMBER_GT_NUMBER_END = 1 AND OBJECTID = ' + str(row.getValue(oid))) as sCur: for x in xrange(int(row.getValue(number_end_Field2) - 1), int(row.getValue(number_Field2))): print x + 1 with arcpy.da.InsertCursor(featureClassCopy, fieldnames) as iCur: for row in sCur: iCur.insertRow(row) row = rows.next()
GIS data (FileGDB) and python script here