Hi,
I have an Arcade expression in which I would like to look through all features for calculation.
I start my expression as:
var Zoning = FeatureSetByName($layer,["City"],true);
I would like to use the variable 'Zoning' to loop in order to calculate in each $feature using the 'City' attribute and the geometry (hence 'True')
In Arcade, I though I could simply point to the current layer using $layer but it does not work!
For info, I am using this Arcade expression in Calculate Field in Model Builder and I cannot easily reference the $datastore name as it is dynamic.
Any help appreciated
FeaturesetByName() asks for a Featureset Collection. $layer is a Featureset (the Featureset that the current $feature belongs to).
To loop through each feature in the current layer, you can just use the $layer global like this:
for(var f in $layer) {
// do something with f
}
Hi,
Finally, I am trying to use the $layer global variable to loop through all features in order to sum acreage per cities. The Arcade expression makes an initial distinct list of cities in the $layer and then calculates acreage acreage accordingly for each $feature, as follow:
var myArray = [];
var i = 0;
for(var z in $layer) {
Insert(myArray, i, z.City);
i = i + 1;
}
var myArrayDistinct = Distinct(myArray);
var myArrayDistinctSort = Sort(myArrayDistinct);
var acreage = 0;
for(var a in myArrayDistinctSort) {
for(var z in $layer) {
if (z.City == myArrayDistinctSort[a]) {
acreage = acreage + z.AreaGeodetic(z, 'acres');
}
}
}
return acreage;
but I still get an:
Invalid expression.
Error on line 3.
Object not found $layer
For info, I am using this Arcade expression in Calculate field tool.
Any guess?
I think I found out the reason why global variable $layer gives an Object not found error.
In Field Calculation profile, only $feature and $datastore can be used in Aracde. Not $layer.
https://developers.arcgis.com/arcade/profiles/field-calculation/
As I use this this Arcade expression in Field Calculation in ModelBuilder with a dynamic feature class name, I have no chance to re-use the ModelBuilder variable pointing to my feature class in the Arcade script...
Never mind, I will perform my calculation differently.
Fantastic!
I will try that. I knew there was something easy.
Appreciated