There is this awesome blog by Esri Australia regarding joining multiple features to one feature:
There is also official Esri documentation on this procedure as well:
“Merge rules > Join
A concatenation of input field values. You can use a delimiter to separate the various input values. If no delimiter is used, all values will be joined into one continuous string.”
Analyze > Executing tools > Executing tools using the tool dialog > Special parameter controls:
https://desktop.arcgis.com/en/arcmap/latest/analyze/executing-tools/using-the-field-mapping-control....
Looks like this is also possible with arcpy.SpatialJoin_analysis python tool:
Analyze > Python > Working with sets of data in Python:
https://desktop.arcgis.com/en/arcmap/10.3/analyze/python/mapping-fields.htm
When I use the spatial join tool I am never given the options shown in this blog post. Why am I not seeing the same options?
Hey, this method is helping a lot but I have a question about duplicated attributes resaults.
FID | SHAPE | JOIN COUNT | TARGET FID | CODE |
5 | Polygon | 5 | 4 | 20, 20, 20, 41, 20 |
Is there a way to stop duplicating or to simplify the resault for example instead of having 20, 20, 20, 41, 20 just to accuire only values 20, 41?
Many thanks!
To get rid of duplicated values, you need to run another function on the result. It can't be changed as this is a result of the merge rule.
The code I use is this:
def uniqueValues(the_value, delimiter=","):
"""return unique separated values in order
Useful to run on ArcGIS processes where there is no control on returned values.
For example SpatialJoin, JOIN_ONE_TO_ONE, with FieldMapping Merge Rule = Join
"""
if the_value is None:
return the_value
# Create a Python list by splitting the string on the delimeter
the_list = the_value.split(delimiter)
# Use set to get unique values
unique_values = sorted(set(the_list))
# Reassemble the string from the sorted list
return delimiter.join(unique_values)