Hi, I am trying to create a dashboard where I would spatially query two layers (point and polygon). I need to return the number of points lying in each polygon to a sheet. In Mapviewer this is not a problem using the arcade language, but I have spent many hours in the dashboard with no result. I am attaching the code that works in Mapviewer and I need to get it into Dashboard.
var osoby=FeatureSetByName($map,"Dopravní nehody / Traffic accidents")
var pocetOsob=Count(Intersects(osoby, $feature))
var intersectArea=Intersects(FeatureSetByName($map,"Traffic accidents"),$feature )
var list_pricin= groupBy(intersectArea, "id", {name:"count", expression: "id", statistic: "COUNT"})
var pocet= Count(list_pricin)
return pocet
In Dashboard Data Expressions, you need to return a FeatureSet object for the Dashboard to work with the output.
The scenario you describe, counting points in a polygon, is exactly what is demonstrated in this example expression here: https://github.com/Esri/arcade-expressions/blob/master/dashboard_data/SpatialAggregation.md
Simply replace the layer / field names with your own, and it should work.
Thanks! yes I know this github repository. But it gives me an error . I don't know why I understand what the code is doing, I have gone through the functions, tested if it returns featuresets, but in the for part it gives me an error. I don't know how to debug arcade code
Debugging Arcade is easier in a web environment where you can use the Console function to return intermediate outputs. If your expression is going to work, it's going to have to look a lot like the linked expression from my initial reply. If we amend that expression and add some console functions, we may get a clearer idea of what's working and what isn't. For instance, you could alter the first part of your expression to return the count of features.
// Portal
var portal = Portal('https://www.arcgis.com/');
// Create FeatureSet for polygons
var poly_fs = FeatureSetByPortalItem(
portal,
'312cebfea2624e108e234220b04460b8',
0,
[
'ZONE'
],
true
);
// See if polygons were returned
Console(`${Count(poly_fs)} features in poly_fs.`)
// Create Featureset for points
var pt_fs = FeatureSetByPortalItem(
portal,
'848d61af726f40d890219042253bedd7',
0,
[
'capacity_mw'
],
true
);
// See if points were returned
Console(`${Count(pt_fs)} features in pt_fs.`)