Select to view content in your preferred language

Spatial Join’s hidden trick on how to transfer attribute values in a One to Many relationship

4011
8
04-22-2021 11:26 AM

Spatial Join’s hidden trick on how to transfer attribute values in a One to Many relationship

There is this  awesome blog by Esri Australia regarding joining multiple features to one feature:

https://esriaustraliatechblog.wordpress.com/2015/06/22/spatial-joins-hidden-trick-or-how-to-transfer...

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

 

Comments
MehdiPira1
Esri Contributor

Very useful. Thanks @AndresCastillo 

AndresCastillo
MVP Regular Contributor

Thanks @MehdiPira1 

NR_McIntyreMurphy__GISS_
New Contributor

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?

FelixHGW
New Contributor II

I have the same problem. I can't find this option at ArcGIS Pro. Is there any other solution at ArcGIS Pro to this? 

Thanks!

Bildschirmfoto 2022-04-12 um 15.12.30.png

Luke_Pinner
MVP Regular Contributor

@FelixHGW click on the source tab, not the properties tab

 

Luke_Pinner_0-1649839563565.png

 

FelixHGW
New Contributor II

Ufff. Thanks a lot Luke!

PawełKropielnicki
New Contributor

Hey, this method is helping a lot but I have a question about duplicated attributes resaults. 

FIDSHAPEJOIN COUNTTARGET FIDCODE
5Polygon5420, 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!

MarkBryant
New Contributor III

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)
Version history
Last update:
‎05-12-2021 07:10 PM
Updated by:
Contributors