Hello Again folks,
I feel I may be exhausting my question limit - much appreciation to the community - I am looking into a course.
I'm trying to summarize a field in arcade and get statistics from the other fields for a result similar to this:
Is this possible in Arcade?
I have looked a Paul Bakers post and the Spanish one and many others but I just can't seem to make anything work
I think Groupby is the option but I just don't know get the sums from the other fields
also do I need to use intersect as I want to get results from the whole dataset if so I can intersect with the municipal border as all developments are within
I got this far with this expression (excuse the radon variables!):
var intersectArea = Intersects(FeatureSetByName($map,"Planning_Layers - Development Applications"), $feature)
var treeList = groupBy(intersectArea, "PRStatus",
{name:"count", expression:"PRStatus" , statistic:"COUNT"})
var topFeatures = Top(OrderBy(treeList, "count desc"),10)
var treeList = ''
for (var topFeature in topFeatures) {
treeList += topFeature.PRStatus + " (" + topFeature.count + ")" + TextFormatting.NewLine
}
return treeList
Thanks again
Aaron
You're right,
GroupBy
is what you want. Since you're just grouping by a single field, and performing basic sums, it's not too complex.
Personally, I find it's easier to create the statistics parameter separately, for the sake of keeping everything straight.
var stats_list = [
{ name: 'Count_PRStatus', expression: 1, statistic: 'COUNT' },
{ name: 'Sum_Units', expression: 'Units', statistic: 'SUM' },
{ name: 'Sum_SingleD', expression: 'SingleD', statistic: 'SUM' },
GroupBy(intersectArea, "PRStatus", stats_list)
If you're looking to just return statistics from the entire dataset, there's not really a need to intersect. That being the case, you might adjust your
FeatureSetByName
function as follows:
FeatureSetByName($map,"Planning_Layers - Development Applications", ['field1', 'field2', etc], false)
Including a field list tells the script to grab only the fields you need, and setting the
includeGeometry
parameter to
false
will improve your script performance a lot by not loading the feature geometry and just working with the attributes separately.
Then just use
GroupBy
with the featureset directly.
WOW thanks!!!!
close!!
(FeatureSetByName($map,"Planning_Layers - Development Applications", ['PRStatus', 'Units', 'SingleD'], false)
var stats_list = [
{ name: 'Count_PRStatus', expression: 1, statistic: 'COUNT' },
{ name: 'Sum_Units', expression: 'Units', statistic: 'SUM' },
{ name: 'Sum_SingleD', expression: 'SingleD', statistic: 'SUM' },
]
GroupBy("PRStatus", stats_list)
Return Stats_list
what did I miss?
It should be
FeatureSetByName(...)
, so try taking the parenthesis off of the front. That was a typo in my earlier response.
Also, you'll still need to bring the FeatureSet into the
GroupBy
function, so assign the featureset to its own variable, then give that variable as the first parameter of
GroupBy
.
my apologies
what am I not doing...?
Thanks
var planStat = (FeatureSetByName)($map,"Planning_Layers - Development Applications", ['PRStatus', 'Units', 'SingleD'], false)
var stats_list = [
{ name: 'Count_PRStatus', expression: 1, statistic: 'COUNT' },
{ name: 'Sum_Units', expression: 'Units', statistic: 'SUM' },
{ name: 'Sum_SingleD', expression: 'SingleD', statistic: 'SUM' },
]
GroupBy(planStat,"PRStatus", stats_list)
I get this
Execution Error:
h.charAt is not a function
keep getting error
Execution Error:
Illegal Value: GroupBy
This is the layer in the map that I am using the expression on: Planning_Layers - Development Applications - Master
should this be something different like the map name...?
var planStat = FeatureSetByName($map,"Planning_Layers - Development Applications - Master", ['PRStatus', 'Units', 'SingleD'], false)
var stats_list = [
{ name: 'Count_PRStatus', expression: 1, statistic: 'COUNT' },
{ name: 'Sum_Units', expression: 'Units', statistic: 'SUM' },
{ name: 'Sum_SingleD', expression: 'SingleD', statistic: 'SUM' },
]
GroupBy(planStat,"PRStatus", stats_list)
Return stats_list
thanks!!
Thanks for all your help Josh but I cannot work out this syntax for the return... I will keep trying..
var planStat = FeatureSetByName($map,"Planning_Layers - Development Applications - Master", ['PRStatus', 'Units', 'SingleD'], false)
var stats_list = [
{ name: 'Count_PRStatus', expression: 1, statistic: 'COUNT' },
{ name: 'Sum_Units', expression: 'Units', statistic: 'SUM' },
{ name: 'Sum_SingleD', expression: 'SingleD', statistic: 'SUM' },
]
Return GroupBy(planStat,"PRStatus", stats_list);
error
Execution Error:
Illegal Value: GroupBy
or this way - Return; GroupBy(planStat,"PRStatus", stats_list);
gives me this:
thanks again Aaron