"MODE" Merge Rule and some problem in a Spatial Join

388
1
04-11-2013 06:11 AM
PasqualeLanera1
New Contributor
Hi.
I have this problem.
In a Spatial Join the merge rules allow you to specify how values from two or more input numeric fields are merged into a single output value.

In a feature class (FC) I have 4 point features that have this value for the field "Alert_Contaminant":

ID Alert_Level_Contaminant
1           2
2           2
3           3
4           3

If I do a Spatial Join between this FC (join fetures) and a Grid (target), I have to choose for the join features fields, "Alert_Level_Contaminant", the Merge Rule.
I choose the "mode" merge rule because I want the most frequent value. But when two value have the same frequency what value for default the overlay tool choose ?
I want to that between the two values ??????with the same frequency is chosen the one with the highest value. Is it possible ?
Maybe with Python ?
Someone could you help me ?
0 Kudos
1 Reply
DouglasSands
Occasional Contributor II
Hi Pasquale,

I saw this post while researching doing something similar. After a quick test, it looks like ArcGIS (running 10.1) will pick the lowest value when the frequencies for any two values are the same. So for Values of [1, 1, 2, 2, 5], ArcGIS will select 1 as the mode. Similarly, for values like [5, 6, 7, 8, 12], ArcGIS selects 5 as the mode.

Regarding your second question, you could do something in python to handle this, but depending on how comfortable you are with a search cursor in python / arcpy, this could be a bit of a challenge. Unfortunately, it doesn't seem to be as simple as finding a setting that you can change.

I haven't tested the code below (my needs were ok with the minimum value), but the code below might be able to do what you are looking for, with perhaps some modification. (ArcGIS 10.1+):
def get_max_mode_candidate(path_to_dataset, value_field):
    mode_dict = {}
    with arcpy.da.SearchCursor(path_to_dataset, [value_field]) as get_mode:
        for record in get_mode:
            val = record[0]
            if val in mode_dict:
                freq = mode_dict[val]
                freq += 1
                mode_dict[val] = freq
                del freq
            else:
                mode_dict[val] = 1
    max_count = 0
    mode_candidates = []
    for val in mode_dict:
        if mode_dict[val] > max_count:
            mode_candidates = [val]
        elif mode_dict[val] == max_count:
            mode_candidates.append(val)
        else:
            pass
    max_mode = max(mode_candidates)
    
    return max_mode


Hope you were able to find a solution that worked for your data,
-Russell

Hi.
I have this problem.
In a Spatial Join the merge rules allow you to specify how values from two or more input numeric fields are merged into a single output value.

In a feature class (FC) I have 4 point features that have this value for the field "Alert_Contaminant":

ID Alert_Level_Contaminant
1           2
2           2
3           3
4           3

If I do a Spatial Join between this FC (join fetures) and a Grid (target), I have to choose for the join features fields, "Alert_Level_Contaminant", the Merge Rule.
I choose the "mode" merge rule because I want the most frequent value. But when two value have the same frequency what value for default the overlay tool choose ?
I want to that between the two values �??�??with the same frequency is chosen the one with the highest value. Is it possible ?
Maybe with Python ?
Someone could you help me ?
0 Kudos