☀Everything Automotive, Tested & Explained Stories

ArcGIS Arcade If-Statement Examples

By

ArcGIS Arcade is a powerful scripting language integral to ArcGIS that allows you to work with map features and perform complex calculations. Conditional statements, including if, else if, and else, are crucial in Arcade scripting to create logic that reacts to different values or situations. Let's delve into some practical examples of if statements in ArcGIS Arcade.

Using if-else statements, you can create rules that dictate the behavior of your script based on specific conditions. This dynamic functionality helps tailor your scripts to suit diverse operational needs within the GIS environment.

Basic If Statement Syntax

The fundamental structure of an if statement comprises two components: the condition and the expression to execute if the condition is true. Here's a simple example:

ArcGIS Urban 101 – Projects and Plans
ArcGIS Urban 101 – Projects and Plans
an image of a website page with maps
an image of a website page with maps
QGIS vs ArcGIS Pro
QGIS vs ArcGIS Pro

[ifPARAM < 0 then return 'Negative' else return 'Non-negative' end]

Understanding Parameters

Parameters in Arcade are values you feed into your scripts, often to guide their behavior. In the example, ifPARAM represents a parameter. The script will return 'Negative' if the value of ifPARAM is less than 0, and 'Non-negative' otherwise.

How to Use ArcGIS Pro to Assess Landslide Susceptibility
How to Use ArcGIS Pro to Assess Landslide Susceptibility
a computer screen with a map on it and an image of the area that is highlighted
a computer screen with a map on it and an image of the area that is highlighted
the words quick tips for mastering the arcis story maps builder on a gray background
the words quick tips for mastering the arcis story maps builder on a gray background

Now, let's apply this structure to real-world scenarios.

Example Uses of If Statements in ArcGIS Arcade

If statements are essential in creating rules for symbolizing features, labels, or even performing custom calculations.

Symbolizing based on a Numeric Field

You can use if-else statements to symbolize features based on numeric values in a field. For instance, to symbolize park areas based on their size:

A Complete Beginner's Guide to ArcGIS Desktop (Part 3)
A Complete Beginner's Guide to ArcGIS Desktop (Part 3)
Client Challenge
Client Challenge
a large city map is shown with red and blue buildings on it's sides
a large city map is shown with red and blue buildings on it's sides
What is ArcGIS? - SlideServe
What is ArcGIS? - SlideServe
Client Challenge
Client Challenge
ArcGIS StoryMaps Gallery | Examples from the StoryMaps community
ArcGIS StoryMaps Gallery | Examples from the StoryMaps community

[if size < 10 then 'Small' else if size < 50 then 'Medium' else 'Large' end]

This script will classify parks into 'Small', 'Medium', and 'Large' based on their size.

Conditional Labeling

If statements can also manage labeling. For instance, you might want to display the label 'Ranger Station' for all fire lookout points, unless they're staffed, in which case you want to display both 'Ranger Station' and the staff name:

QGIS Workflow
QGIS Workflow
\
\
a map that has many different colored lines on it, including the city's streets
a map that has many different colored lines on it, including the city's streets
Top 10 ArcGIS Pro Tutorial Lesson
Top 10 ArcGIS Pro Tutorial Lesson

[if hasStaff then 'Ranger Station (' + staffName + ')' else 'Ranger Station' end]

This script will label fire lookout points as 'Ranger Station' if they don't have staff. If they do, it adds the staff name in parentheses.

Understanding and effectively using if statements in ArcGIS Arcade is key to creating powerful and versatile scripts. The possibilities range from creating dynamic map layouts to performing complex calculations, all driven by conditional logic.

Now that you've seen some practical examples, start exploring and experimenting with Arcade scripts in your workflows. The more you practice, the more adept you'll become at harnessing the power of conditional logic to drive your GIS processes.