You work hard, you play hard. You spend time and energy managing large complex datasets, then head to one of your favorite spots to unwind. Now you can get even more free time by prepopulating fields in forms in Map Viewer. In this article, we’ll show you how to use an Arcade expression to automatically pull attributes from one layer into another. We’ll walk you through authoring the form, creating an expression, provide you with a code snippet, and explore a map so you can take it for a spin. Let’s dive in.
FeatureSet
Arcade is a portable, lightweight, expression language used across the ArcGIS platform that can be used to do things like perform calculations or manipulate text. It can be used in pop-ups, labels, for field calculation and more.
FeatureSet
is a function in Arcade that creates a set of features from a layer (or table) that can be used in calculations. Previously, you could use FeatureSet functions to pull values from other layers into a pop-up. With the Fall 2022 update of ArcGIS Online, we’ve expanded its use to smart forms, enabling you to pull values from another layer into a form while editing. This process automates data collection for that field, making editing more efficient while improving accuracy.
Example
Let’s say you’re a GIS Analyst in Honolulu working on an addressing project. You need to create a point for each new address and provide attribute information for the new point, including a zoning code for the location. No problem, using Arcade we’ll fetch that information from another layer that contains zoning codes and paste it right into the form when creating a new point.
Step 1: Author a map
You’ll need a map with at least one editable layer, and a reference layer that contains the information you want. In this example, we have the following layers:
- Editable layer: New Address Point
- Reference layer: Zoning Codes
Let’s take a look inside the attribute table for Zoning Codes. The field ‘zone_class’ contains the information we want. We need to take note of both the layer name and the field name, as we’ll use these later in our Arcade expression.
Step 2: Author a form
- With the editable layer selected, click Forms on the Settings (light) toolbar.
- Add fields to the form by dragging fields like Address and Zoning District onto the form.
Step 3: Author the expression
Next, we’ll open the Arcade editor window following these steps:
- Inside the Form builder window, Select the field you want to calculate (Zoning District).
- In the Properties Pane on the right, scroll down to Calculated expressions.
- Click the gear icon to open Calculated expressions.
- Click New expression.
- The Arcade editor window appears. This is where you can write and test expressions.
Let’s break it down. In this expression, we do the following:
- Use a variable to define a FeatureSet using the layer name and the field name
- var <VariableName1> = FeatureSetByName($map, “<LayerName>”, [“<FieldName>”])
2. Use the function ‘Intersect’ to locate the data from the feature that intersects a new address point ($feature)
- var <VariableName2> = First(Intersects($feature, <VariableName1>))
3. If the specified field contains a value, we return the value
- if (!IsEmpty(variable2)) {return variable2[‘field name’]} else {return null}
Below is a snippet you can copy, paste, and modify:
Make this expression your own following these steps:
- Give your expression a title. This is especially important so you can identify expressions when you have more than one.
- Copy, paste, and customize the code snippet.
- Replace the “layer” and [‘field’] names to match your layer.
- Click Run to ensure the expression is working.
- Click Done to close the Arcade editor.
- Click OK to close the form.
Best practice: When a feature set is made up of point or line features, we recommend adding a small buffer to those features to ensure that the snapping tolerance is large enough for the intersect to be detected properly. You can do this using the Buffer() function in addition to Intersect.
Example:
- var <VariableName2> = Intersects(<VariableName1>, Buffer($feature, <BufferSize>))
Step 4: Try it out
Open this map to give it a spin following these steps:
- Click Edit on the Settings (light) toolbar. The Editor pane appears.
- Under Create features, select New Address Point.
- Click to place a point on the map.
The form opens. The field ‘Zoning District’ is automatically populated with the correct zoning class.
Summary
And there you have it! You’ve just seen how you can use Arcade expressions to fetch values from other layers. We walked through configuring a form and authoring an expression using the Feature set function. This ability enables you to expedite data editing while ensuring data integrity so you can spend more time at the beach and less time managing data.
Now, go catch that wave!
Commenting is not enabled for this article.