Combining multiple attributes into one field

14397
14
12-14-2017 03:00 PM
CarlTownsend2
New Contributor III

Hi, I have an interesting problem. I have two separate polygon layers in ArcMap/ArcPro One layer, B, is made up of smaller polygons and contained within another layer, A. B contains an EXT attribute, which can be different, so for example layer B has three polygons completely contained by layer A, and these three polygons have different EXT attributes, say 1, 4 and 7. I would like to merge these EXT attributes into layer A, so that layer A has a field called EXT, containing 1,4,7 from the layer B.

There is nothing unique between these two layers so I cannot do a relate or table join, I can only do a join based on spatial location, or try using dissolve, merge geoprocessing tools. I've tried all of these and haven't gotten the result I want. Is this actually possible? I don't want to sum, or average or range these EXT values. Iwant to preserve them.  I want them all in a new EXT field for A, preferably separated by a space or comma.

Thanks

0 Kudos
14 Replies
DanPatterson_Retired
MVP Emeritus
z = 'coal, limestone, sandstone, coal, coal, limestone, slate'

a0 = ", ".join(sorted(set([i.strip() for i in z.split(",")])))

a0
Out[181]: 'coal, limestone, sandstone, slate'‍‍‍‍‍‍

I tried to cram as many useful python things in as I could...

Z is your field of course and needs to be replaced with !YourFieldNameHere! for a python parser

DushyantDesai
New Contributor

This is exactly I am looking for from long time. It is also worth to note change the field size from  properties to required length since by default it is 255 text if your merge value is more than that it will skip that record.

0 Kudos
MichelleWilliams1
Occasional Contributor III

Would Esri add a button to remove duplicates? It would make the end-users life so much easier. 

0 Kudos
DanPatterson_Retired
MVP Emeritus

set

s = "a;Michelle;a;a;a;a;a;a;a;a;a;Williams"

sp = list(set(s.split(";")))

sp
['Williams', 'Michelle', 'a']

then you can sort and/or join as needed

MichelleWilliams1
Occasional Contributor III

Thank you for your help. My level of code is basic, so I’m not sure what to do with this.

Re: Attatched Code

I used this code with no issues, maybe it will help folks on this thread.

I added the source at the top of the code.

Michelle Williams

Geospatial Technical Specialist

Geospatial Analysis | Real Properties | Transmission & Distribution

PAX 63217 | (909) 274-3217

M. 951-538-3735 | E: michelle.williams@sce.com<mailto:michelle.williams@sce.com>

2 Innovation Way, 2nd Floor, Pomona, CA 91768

P Please consider the environment before printing this email.

0 Kudos