Categories
Webinars

Field Calculator Webinar

Video

Downloads

  1. Map Package
  2. Powerpoint (PDF Version)

Code Snippets

If you want to learn Python, here are the resources I mentioned during the webinar. If you ask most software developers the best way to learn to code, they’ll tell you to find a project you care about and figure out how to solve it with code – that will force you to learn what you need. The code snippets from the webinar are below.

Fire Severity

Here is the code snippet from the powerpoint – there is no data in the map package to match this, though if you want to test it out, you can manually build a table in ArcMap to test it with. If you want to improve it, you can try changing the algorithm to a different method of combining the values, add other variables, etc

def get_severity(intensity, burn_rate):
  severities = { 1: “Minimal”, 2: “Low”,
          3: “Medium”, 4:”High”,
          5:”Extreme”}
  base_severity = intensity + burn_rate
  
  if base_severity > 5:
    base_severity = 5
    
  return severities[base_severity]
  
get_severity(!INTENSITY!, !BURN_RATE!)

Meadows

def classify_meadow(catchment_area, elevation):
    elevation_classification = None
    if elevation > 2500:
        elevation_classification = "High altitude"
    else:
        elevation_classification = "Low altitude"

    catchment_classification = None
    if catchment_area > 1000000:
        catchment_classification = "High flow"
    else:
        catchment_classification = "Low flow"

    classification = "{}, {}".format(elevation_classification, catchment_classification)

    return classification

Addresses

The map package has materials for field calculator that we didn’t have time to cover during the webinar. If you’d like to try out some of the field calculator snippets below for extra practice using the data in the map package, see what you can do to split and combine address fields!

# A quick and dirty way to combine fields to a single address, but it has some issues!
!street_number! + " " + !street_name! + " #" + !unit_number! + ", " + !city! + ", " + !state! + " " + !zip!

#this solves a few issues, but maybe not all of them
str(!street_number!) + " " + !street_name! + " #" + str(!unit_number!) + ", " + !city! + ", " + !state! + " " + !zip!

#this method uses Python string formatting to merge
"{num} {street} #{unit}\n{city}, {state} {zip}".format(num=!street_number!, street=!street_name!, unit=!unit_number!, city=!city!, state=!state!, zip=!zip!)

# Checks to see if we have a unit before combining so that we don't get stray pound/hash characterrs
def make_address(street_number, street_name, unit, city, state, zip):
  if unit is not None:
     unit_string = "#{}".format(unit)
  else:
     unit_string = ""
    
  address = "{num} {street} {unit}\n{city}, {state} {zip}".format(num=street_number, street=street_name, unit=unit_string, city=city, state=state, zip=zip)

  return address
  
make_address(!street_number!, !street_name!, !unit_string!, !city!, !state!, !zip!)

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.