The goal of this code is to find the top 3 most planted trees in each polygon and rank them in a popup. The code below accomplishes that, but it returns the code of the domain and not the description.
For example, I want the list to look like this "1. Maple 2. Oak 3. Hickory", but arcade returns this instead"1. AC 2.QU 3. CA".
I have attempted to use DomainName to return the description, but I am having difficulty. When I run the code below in an attempt to return the description, nothing is returned. Please help me return the description and not the code for this feature class.
var trees = FeatureSetByName($map, "Trees - Trees")
var countspecies = Intersects(trees, $feature)
var stats = Groupby(countspecies, "commonname",[
{name: "total" ,expression: "commonname", statistic: 'COUNT'}
])
var topspecies = Top(OrderBy(Filter(stats, "commonname <> ''"), "total desc"), 3)
var result = 'The top species in this tract are:'
var num = 0
for (var item in topspecies){
num++
var num_species = item["total"]
var species_name = DomainName(item,FeatureSetByName($map, "Trees - Trees"), "commonname")
result += TextFormatting.NewLine + num + ". " + " " + species_name + " " + num_species + " " + "planted"
}
return result
Solved! Go to Solution.
What you have to do is get the domain's codedValue array and for each item, loop through that array to get the correct domain name.
This should work
var trees = FeatureSetByName($map, "Trees - Trees");
var countspecies = Intersects(trees, $feature);
var stats = Groupby(countspecies, "commonname",[
{name: "total" ,expression: "commonname", statistic: 'COUNT'}
]);
var topspecies = Top(OrderBy(Filter(stats, "commonname <> ''"), "total desc"), 3);
var result = 'The top species in this tract are:';
var num = 0;
var codedValues = Domain(trees, 'commonname').codedValues;
for (var item in topspecies){
num++;
var num_species = item["total"];
var species_name;
for (var i in codedValues){
if (codedValues[i].code == item['commonname']) species_name = codedValues[i].name;
}
result += TextFormatting.NewLine + num + ". " + " " + species_name + " " + num_species + " " + "planted";
}
return result
What you have to do is get the domain's codedValue array and for each item, loop through that array to get the correct domain name.
This should work
var trees = FeatureSetByName($map, "Trees - Trees");
var countspecies = Intersects(trees, $feature);
var stats = Groupby(countspecies, "commonname",[
{name: "total" ,expression: "commonname", statistic: 'COUNT'}
]);
var topspecies = Top(OrderBy(Filter(stats, "commonname <> ''"), "total desc"), 3);
var result = 'The top species in this tract are:';
var num = 0;
var codedValues = Domain(trees, 'commonname').codedValues;
for (var item in topspecies){
num++;
var num_species = item["total"];
var species_name;
for (var i in codedValues){
if (codedValues[i].code == item['commonname']) species_name = codedValues[i].name;
}
result += TextFormatting.NewLine + num + ". " + " " + species_name + " " + num_species + " " + "planted";
}
return result
This is great, thank you so much for your help!!