AnsweredAssumed Answered

Transferring attributes from duplicate geometry

Question asked by qvt2_pdxedu on Jan 31, 2020
Latest reply on Feb 3, 2020 by qvt2_pdxedu



I have a conceptual question that I am trying to figure out fast and efficient methods for coding in arcpy / Python.



I have a geometry dataset with attributes, and some of this geometry is identical in shape, but not in attribute.


I'd like to identify the geometrically identical features, usually a pair, and then transfer an attribute from one feature to the other within that pair.

To wit, in the below image:

There are two geometrically identical lines between points B / E, though they may possess differing attributes in one specific field. I'd like to keep all existing attributes in each line, but also add the attributes in that specific field from each of the lines to the other into a newly created field.

Method A:

One way I've determined to do this is through the use of UpdateCursors, as in the code snippet below:

fieldNames = ['GROUPID', 'ATTRB_1', 'DUPL_ATTRB', 'SHAPE@']
with arcpy.da.UpdateCursor(inputfc, fieldNames) as aList:
    for a in aList:
        with arcpy.da.UpdateCursor(inputfc, fieldNames) as bList:
            for b in bList:
                if a[0] != b[0] and a[-1] == b[-1]:
                    a[2] = b[1]
                    b[2] = a[1]
del a, aList, b, bList

Here, the existing attribute that will remain for each feature is "ATTRB_1," and there is a new field created called "DUPL_ATTRB" where the geometric twin would thus transfer its attribute (ATTRB_1). 

But I am finding that this method takes a lot of time, especially for large datasets with upwards of tens of thousands (>10,000) of features. 

Other methods?

I know this can be done with a SpatialJoin and some fieldMapping, but I'm having trouble understanding how to properly build the fieldMapping object to do this. However, I feel that the SpatialJoin may be significantly faster than the nested UpdateCursor method that was my initial attempt. 


Are there other methods that can be done to achieve this same goal more quickly and efficiently? 


Thanks in advance,