Arcade - split comma separated attributs in dictionary and show in maps

218
5
a month ago
SimoneMoretti_MRC
New Contributor II

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 use this expression in a category selector and this works fine. But in the end, when I select a category, the geometry don't show in the map. (Ex: If I choose Boucherie, I want all the points in this category to show in the map).
Anyone know what I'm forgetting? Can someone have one idea how improve my arcade expression to do that?

 

0 Kudos
5 Replies
jcarlson
MVP Regular Contributor

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?

- Josh Carlson
Kendall County GIS
0 Kudos
SimoneMoretti_MRC
New Contributor II

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

0 Kudos
DavidPike
MVP Frequent Contributor

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.

0 Kudos
SimoneMoretti_MRC
New Contributor II

Thanks for your answer DavidPike,
Do you know what is the function to request the geometry in this case?

 

 

0 Kudos
DavidPike
MVP Frequent Contributor

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)