Hello all,
I am using ArcGIS Online, and has 2 layers in my map.
1) USA Census States (Living Atlas), with so many fields, and our interest is in "Population" field
2) Points (Hosted Feature Layer), with a Test field
My objective is to create points in some states and auto-populate the test field with its Population from USA Census States layer in the map.
I tried using Arcade in smart forms, but seems like there is some roadblock. Either this is not supported yet on AGOL or I am doing something wrong?
Arcade I used:
// Access the USA States polygon layer with population information
var states = FeatureSetByName($map, "USAStatesLayer", ["population_field"]);
// Find the first USA state polygon that contains the current point
var intersecting_state = First(Filter(states, Contains(Geometry($feature), Geometry($layer))));
// If an intersecting state polygon is found, return its population value
if (!IsEmpty(intersecting_state)) {
return intersecting_state["population_field"];
} else {
return "No Population Data";
}
I have also tried using Intersect function, but fails.
Is there any other way of achieving this? My end goal is to use this method for field maps data collection, so that when a point is collected by field workers, the population data is automatically filled in the collected records.
Any help on this would be highly appreciated!!
Solved! Go to Solution.
You're *nearly* there. The Filter function acts against attributes, and takes a SQL expression, not other functions.
The Contains function (and any other spatial overlay) is a filter already, just a spatial one. The omitting the filter and just use Intersects. The output of Intersects($feature, states) will be the state containing the point, and First will get that feature for you.
Also, when you have a true/false condition, you can use Iif instead of an if/else block.
// Access the USA States polygon layer with population information
var states = FeatureSetByName($map, "USAStatesLayer", ["population_field"]);
// Find the first USA state polygon that contains the current point
var intersecting_state = First(Intersects($feature, states))
// If an intersecting state polygon is found, return its population value
return Iif(
!IsEmpty(intersecting_state),
intersecting_state["population_field"]
"No Population Data"
)
You're *nearly* there. The Filter function acts against attributes, and takes a SQL expression, not other functions.
The Contains function (and any other spatial overlay) is a filter already, just a spatial one. The omitting the filter and just use Intersects. The output of Intersects($feature, states) will be the state containing the point, and First will get that feature for you.
Also, when you have a true/false condition, you can use Iif instead of an if/else block.
// Access the USA States polygon layer with population information
var states = FeatureSetByName($map, "USAStatesLayer", ["population_field"]);
// Find the first USA state polygon that contains the current point
var intersecting_state = First(Intersects($feature, states))
// If an intersecting state polygon is found, return its population value
return Iif(
!IsEmpty(intersecting_state),
intersecting_state["population_field"]
"No Population Data"
)
Thank you so much @jcarlson
Just adding this Esri resource here in case others come looking for a solution: