Select to view content in your preferred language

# Transferring attributes from duplicate geometry

686
4
01-31-2020 04:07 PM
New Contributor II

Hello,

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

Given:

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

Objective:

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]
bList.updateRow(b)
aList.updateRow(a)
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?

4 Replies
MVP Emeritus

on the geometry field, you can then do what you want with the output attributes (join etc)

If you then want to get rid of the duplicate geometry

Delete Identical—Data Management toolbox | ArcGIS Desktop on the geometry field

New Contributor II

Just to understand a little bit better: the process you are suggesting would be to run the Find Identical tool, output only the duplicates, run the nested Search/UpdateCursor loop that I proposed on the output, and then join that table back to the original using the FID field?

MVP Emeritus

Did you try that? Just don't use Delete Duplicates on original files if that is in your plan until you know everything works.

New Contributor II

I'm going to try it now, though part of my initial concern was that I don't know how to use the FieldMapping objects that the join tools require. I guess I will have to learn, and I will attempt to do the regular Spatial Join as well, as it seems that does the job as well (at least it does in ArcGIS Pro without any Python scripting). I will let you know which I find is faster for the large datasets I am looking at.