Hello,
I have a polygon layer (my city's districts) and a point layer (new trees planted in my city). The tree points are crowd-sourced from a survey 123, it is therefore a shared update layer with sync enabled.
I want to display how many tree points are planted per district in a dashboard, perhaps in a list. For instance:
District A: 35 new trees
District B: 2 new trees
How can I connect the district polygon layer and the tree point layer in dashboard?
Here is what I have attempted so far:
In map viewer I have successfully done this using arcade in popup for the district polygon layer:
var treepoints= FeatureSetByName($map, "new_tree_points")
var numberoftrees= Count(Contains(treepoints,$feature))
return numberoftrees
This expression does not function in dashboard because I cannot figure out how to refer to another layer than the one I have selected. I have understood that the arcade profiles are different for map viewer and dashboard. In both dashboard List settings and Data expressions I have tried FeatureSetByPortalItem, but I get error message "Parse Error:featuresetbyportalitem is not available". My AGOL organization has not yet implemented Portal, is this the reason I cannot refer to a portal item?
I have also tried to calculate a field with this value and just show the new field in the dashboard list, but I have the same challenge with figuring out how to refer to another layer/feature. I also understand that Arcade cannot be used on hosted features with sync enabled so this may not be the way to go. Any pointers are appreciated.
Thanks in advance.
Try this
var treepoints= FeatureSetByName($map, "new_tree_points")
var numberoftrees= Count(Contains($feature,treepoints))
return numberoftrees
It really depends on where in the Dashboard you're using Arcade, and what exactly you're trying to do with it. If all you want is a list with a count in it, that's not terribly difficult, but accessing other layers in a Dashboard Arcade profile does require a bit more work than usual.
This example should give you a good idea:
// Portal
var portal = Portal('https://www.arcgis.com/');
// Create FeatureSet for polygons
var poly_fs = FeatureSetByPortalItem(
portal,
'312cebfea2624e108e234220b04460b8',
0,
[
'ZONE'
],
true
);
// Create Featureset for points
var pt_fs = FeatureSetByPortalItem(
portal,
'848d61af726f40d890219042253bedd7',
0,
[
'capacity_mw'
],
true
);
// Create empty feature array for output
var features = [];
// Iterate over time zones
for (var poly in poly_fs) {
// Filter points by polygon
var pts = Contains(poly, pt_fs);
// Create feature with aggregated values
var feat = {
'attributes': {
'tz': poly['ZONE'],
'pt_cnt': Count(pts)
}
};
// Push feature into array
Push(features, feat);
};
// Create dict for output FeatureSet
var out_dict = {
'fields': [
{'name': 'tz', 'alias': 'Time Zone', 'type': 'esriFieldTypeFloat'},
{'name': 'pt_cnt', 'alias': 'Number of Power Plants', 'type': 'esriFieldTypeInteger'}
],
'geometryType': '',
'features': features
};
// Convert dictionary to feature set.
return FeatureSet(Text(out_dict));
And the output: