AnsweredAssumed Answered

Insert Cursor populating length field with zeros

Question asked by deleted-user-qSBucAQszJ_6 on Mar 16, 2018
Latest reply on Mar 19, 2018 by deleted-user-qSBucAQszJ_6

Good afternoon,


I've been working on a script that will compare two different feature classes and move changes from the one that has been edited to the target feature class. I got most of my logic from this forum post Comparing Two Feature Classes and Updating One of Them. The script is working but it leaves out the actual geometry so all that is left in the Shape_Length field is "0" so I get records in the table but no actual geometry. You can see in the below images the zeros and the street that should be copied to the target feature class the green line should be covered by the records that have a zero in the Shape_Length field.




I think there is something wrong with the search cursor/insert cursor that I'm using but not 100% sure. My code is below.



def creatingMatchingFieldList(fc1, fc2):
    lst1 = [ for fld in arcpy.ListFields(fc1)]
    lst2 = [ for fld in arcpy.ListFields(fc2)]
    return list(set(lst1) & set(lst2))

def createWhereClause(fc, fld_name, value):
    Should return 'GGMID = 20412.0'
    can be some other value...
    if len(arcpy.ListFields(fc, fld_name)) == 1:
        fld = arcpy.ListFields(fc, fld_name)[0]
        if fld.type == "String":
            where = "{0} = '{1}'".format(arcpy.AddFieldDelimiters(fc, fld_name), value)
            where = "{0} = {1}".format(arcpy.AddFieldDelimiters(fc, fld_name), value)
    return where

def getPrimaryFieldValues(fc, field):
    return [r[0] for r in arcpy.da.SearchCursor(fc, [field])]

def getSelectCursor(fc, flds, whereClause):
    return arcpy.da.SearchCursor(fc, flds, whereClause)

def diff(a, b):
    return list(set(a) - set(b))

try:"Creating a list of field names that are in both fcs...")
    flds = creatingMatchingFieldList(NewStreets, OLDStreets)

    sourceValues = getPrimaryFieldValues(NewStreets, fieldName)
    destinationValues = getPrimaryFieldValues(OLDStreets, fieldName)

    additions = diff(sourceValues, destinationValues)

    deletions = diff(destinationValues, sourceValues)

    workspace = NetworkDatasetGDB"Creating the insert cursor and adding the New street lines to the Old Street Lines...")
    with arcpy.da.Editor(workspace) as edit:
        insertRows = []
        for a in additions:
            where = createWhereClause(NewStreets, fieldName, a)
            Row = getSelectCursor(NewStreets, flds, where)
        with arcpy.da.InsertCursor(OLDStreets, flds) as insertCursor:
            for rec in insertRows:
                for r in rec:
        #edit.stopEditing(True)"Creating the update cursor and updating the old Street Lines with the values from the new Street Lines...")
    with arcpy.da.Editor(workspace) as edit:
        for d in deletions:
            where = createWhereClause(OLDStreets, fieldName, d)
            with arcpy.da.UpdateCursor(OLDStreets, flds, where) as deleteCursor:
                for d in deleteCursor:

If anyone has an idea why the the actual shape is not being inserted with the insert cursor that would be awesome! 




Christopher Long