Are you a rule follower or a rule breaker? We’ve got both in our office (I won’t mention any names…) but we all agree that Attribute Rules in ArcGIS Pro are the types of rules we can get behind. There are three rule types you can use to help keep your data in check: Calculation, Constraint, and Validation. Today I’m going to give some examples of creating and applying Calculation rules. If you’re an ArcMap user, this will look a lot like using Attribute Assistant, but better.
Seven Simple Steps!
Open the Attribute Rules window by clicking on the feature class in the Catalog pane, hovering over “Design” and selecting “Attribute Rules” from the drop down list
Click “Add Rule” button
Name the rule and provide a description
Choose the field to which the rule will be applied from the drop down menu.
Enter the Arcade expression.
Check what will trigger the calculation (Insert, Update, or Delete)
Save!
Now you can create or edit a feature and watch as the Attribute Rules help keep your data accurate and save you time!
Example Arcade Expressions
So obviously step #5 above is where all the magic happens. The good people of the internet have been instrumental in helping me create Arcade expressions that meet my needs. Below are the expressions I used to perform each of the calculations I needed. Copy and paste and edit to make them work for you!
Populate ID Field
Notes: For this to work, you have to create a Database Sequence, which is explained here.
// This rule will create a new unique id when a site address point is created // Define the leading text and the delimiter for the ID var prefix = "SITE" var suffix = "@county911.com" //Ensure the ID is not already set, if it is, return the original id //Enter name of database sequence inside quotes if (IsEmpty($feature.Site_NGUID)) { return Concatenate([prefix, NextSequenceValue("NameOfDatabaseSequence"),suffix], "") } else { return $feature.Site_NGUID }
Convert street type to abbreviation
Notes: This else-if expression can be used for any set of fields where one field’s data needs to be converted to an abbreviation that can’t otherwise be field calculated. I’ve used this for cardinal directions, street types, and city codes.
if ($feature.St_PosTyp == 'AVENUE'){ return "AV" } else if ($feature.St_PosTyp == 'BOULEVARD'){ return "BLVD" } else if ($feature.St_PosTyp == 'COURT'){ return "CT" } else if ($feature.St_PosTyp == 'CIRCLE'){ return "CIR" } else if ($feature.St_PosTyp == 'DRIVE'){ return "DR" } else if ($feature.St_PosTyp == 'ESTATES'){ return "EST" } else if ($feature.St_PosTyp == 'LANE'){ return "LN" } else if ($feature.St_PosTyp == 'PARK'){ return "PK" } else if ($feature.St_PosTyp == 'PARKWAY'){ return "PKWY" } else if ($feature.St_PosTyp == 'PLACE'){ return "PL" } else if ($feature.St_PosTyp == 'PLAZA'){ return "PLZ" } else if ($feature.St_PosTyp == 'POINT'){ return "PT" } else if ($feature.St_PosTyp == 'ROAD'){ return "RD" } else if ($feature.St_PosTyp == 'SQUARE'){ return "SQ" } else if ($feature.St_PosTyp == 'STREET'){ return "ST" } else if ($feature.St_PosTyp == 'TERRACE'){ return "TER" } else if ($feature.St_PosTyp == 'TRACE'){ return "TR" } else if ($feature.St_PosTyp == 'TRAIL'){ return "TRL" } else{ return " " }
Concatenate (and Ignore Nulls!)
Notes: This is a great expression to use in attribute rules as well as in field calculator!
//Array to hold values and an index var i = 0; var features = []; //Add value to array if not empty function addvalue(feat) { if (!IsEmpty(feat)) { features[i++] = feat; } } //Add your values addvalue($feature.St_PreDirAbbr); addvalue($feature.St_Name); addvalue($feature.St_PosTypAbbr); addvalue($feature.Post_Comm); //Return a concatenated string with a space between each attribute return Concatenate(features, " ")
calculate latitude and longitude
Notes: This one is great to update those lats and longs automatically when a point is moved.
// use expression below for latitude Geometry($feature).y // use expression below for longitude Geometry($feature).x
Wrap Up
Phew…that was a lot of code. Remember this is just to get you started. There is no end to how these rules can be customized and obviously this is just the tip of the iceberg when it comes to Arcade expressions. Got questions? Suggestions? Awesome ways you’ve used Attribute Rules or Arcade expressions? Email me!