Hello -
I am working in ArcGIS Online Dashboards, and am using the Social Vulnerability Index service from CDC. I would like to create an arcade data expression in dashboards that selects the census tracts that intersect our service area (polygon) and display the number of census tracts in an indicator.
Is this possible?
Thanks,
Leila
Esri has a Github page containing a number of different Arcade expressions. The Aggregate by Spatial Relationship example in the Dashboard section might be what you're looking for.
Thanks @KenBuja - I have seen that, but am still relatively new to arcade especially in dashboards so not quite sure how to implement that.
It is possible. Here's a basic template. Just swap in your layer IDs and field names.
// service areas layer
var fs1 = FeatureSetByPortalItem(
Portal("https://www.arcgis.com"),
// portal item id
"7b1fb95ab77f40bf8aa09c8b59045449",
0, // layer id
["*"], // fields to include
false // include or exclude geometry
)
// census tracts layer
var fs2 = FeatureSetByPortalItem(
Portal("https://www.arcgis.com"),
// portal item id
"6200db0b80de4341ae8ee2b62d606e67",
0, // layer id
["*"], // fields to include
true // include or exclude geometry
);
// output dictionary
var out_dict = {
fields: [
{
name: 'service_area_id', type: 'esriFieldTypeString'
},
{
name: 'number_of_tracts', type: 'esriFieldTypeInteger'
}
],
geometryType: '',
features: []
}
// loop through service areas
for (var f in fs1) {
// get intersected tracts
var xs_tracts = Intersects(f, fs2)
// push service area and count into the output dict
Push(
out_dict['features'],
{
attributes: {
service_area_id: f['service_area_id'],
number_of_tracts: Count(xs_tracts)
}
}
)
}
// return featureset
return FeatureSet(out_dict)