Select to view content in your preferred language

Is it possible to Auto populate a field with underlying layer in ArcGIS Online?

1044
3
Jump to solution
10-08-2024 08:14 AM
Yogesh_Chavan
Frequent Contributor

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!!

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

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"
)

 

- Josh Carlson
Kendall County GIS

View solution in original post

3 Replies
jcarlson
MVP Esteemed Contributor

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"
)

 

- Josh Carlson
Kendall County GIS
Yogesh_Chavan
Frequent Contributor

Thank you so much @jcarlson 

0 Kudos
dsinha
by
Regular Contributor

Just adding this Esri resource here in case others come looking for a solution:

Fetch an attribute from an underlying polygon

0 Kudos