Hi everyone.
I'm trying some advanced arcade expressions in dashboard and I need some help.
My data come from select_mutiple field create in survey 123. My attributes are comma separated (ex: Boucherie, Garage, Friperie) linked to a point geometry element.
With this expression, I'm able to split and store the attribute in a dictionary:
_________
// Reference layer using the FeatureSetByPortalItem() function.
var fs = FeatureSetByPortalItem(Portal('https://www.arcgis.com'), '371113694bd24607b2e9d01e49024944' , 0, ['TypeLocatLabel'], false);
// Empty dictionary to capture each hazard reported as separate rows.
var choicesDict = {'fields': [{ 'name': 'split_choices', 'type': 'esriFieldTypeString'}],
'geometryType': '', 'features': []};
var index = 0;
// Split comma separated hazard types and store in dictionary.
for (var feature in fs) {
var split_array = Split(feature["TypeLocatLabel"], ',')
var count_arr = Count(split_array)
for(var i = 0; i < count_arr; i++ ){
choicesDict.features[index++] = {
'attributes': { 'split_choices': Trim(split_array[i]),
}}
}}
// Convert dictionary to featureSet.
var fs_dict = FeatureSet(Text(choicesDict));
// Return featureset after grouping by hazard types.
return GroupBy(fs_dict, ['split_choices'],
[{ name: 'split_count', expression: 'split_choices', statistic: 'COUNT' }]);
______
I think that part of the problem here is that using Group By does not return any geometry that you can work with. Can you just use the Grouped Features type for your category selector, and omit the grouping function in your expression?
Thanks for your answer jcarlson.
Unfortunately, if I just use Grouped Features I'm not able to read the data correctely.
I'm trying to find a way to return the geometry in the Group By function
I would say there's a few parts to this, you've supplied False to the return geometry parameter of FeatureSetByPortalItem, I haven't needed to do this myself but I can only guess you also have to request the geometry column in the fields parameter of this also.
This geometry then needs to be formed into the JSON dictionary/string as part of "geometry" :
Note this is just my opinion of how it should work rather than from direct experience.
Thanks for your answer DavidPike,
Do you know what is the function to request the geometry in this case?
I would guess it can be done with something like
for (var feature in fs) {
...
//JSON to be passsed into choicesDict["geometry"]
//e.g. 'geometry': ...
featureGeom = Geometry(feature)