1

I'm building electoral maps from mayoral races in ArcGIS over the last 3 election cycles, trying to see if a particular part of town votes like the rest of the town.

There are multiple candidates for mayor and an example table looks like this:

PRECINCT_NUMBER    TOTAL_BALLOTSCAST    CANDIDATE1   CANDIDATE2  CANDIDATE3
           500                  1000           500          300         200
           501                  2000           800          700         500
           502                  1000           400          500         100

I can show how a specific candidate did by precinct by calcuating candidatex / total_ballotcast to give percentages for each precinct, and display the precincts by category of percentage by candidate.

However, I am also trying to show who was the biggest winner in each precinct by percentage and I am not sure how to query the data to reflect this.

Erica
  • 2,399
  • 5
  • 26
  • 34

1 Answers1

1

To accomplish this within ArcMap:

Create a new field (e.g. WINNER). Use field calculator to compare the values from three fields and output the maximum (biggest winner) as follows:

Check "Show Codeblock" to do an advanced python expression in the field calculator tool.

The expression should be:

find_winner(!CANDIDATE1!, !CANDIDATE2!, !CANDIDATE3!)

The pre-logic script code is where you define the function find_winner that the expression is calling:

def find_winner(a, b, c):
    if a > b and a > c:      # if a got more votes than b and c
        return "Candidate 1"
    elif b > a and b > c:    # if b got more votes than a and c
        return "Candidate 2"
    elif c > a and c > b:    # if c got more votes than a and b
        return "Candidate 3"
    else:
        return "TIE?"

Once WINNER is populated with values, it should be straightforward to symbolize your polygons based on that attribute.

Erica
  • 2,399
  • 5
  • 26
  • 34