Select to view content in your preferred language

Need to use DISTINCT for a list, wont work (ARCADE)

1096
3
Jump to solution
08-07-2019 12:04 PM
ClaudiaEspinosa-Villegas
Emerging Contributor

Hello everyone

I am a total newbie and currently learning Arcade. I am trying to pull the names of different bus lines (in a BUS LINES layer) into a pop-up for a different layer (NEIGHBORHOODS) but not have them repeat. The goal is to show the bus lines that are in the neighborhood in question.

The code is as follows:

var result = ""
var i = Intersects(FeatureSetById($map, /* Metro Bus Lines */ "Metro_Bus_and_Rail_1230"),$feature)
for(var f in i){
result += f.RouteName + ", "
}
return result

and get the resulting text (see below). I want the repeats to not show (the bus line appears to be separate transects and not one polyline (not my data)). So for the #33 bus line the name of the line (in red) shows as many times are there are transects within the boundary of the neighborhood of interest. 

35 Downtown LA- WLA Via Washington Bl & Jefferson Bl, 33 Downtown LA - Santa Monica Via Venice Bl, 33 Downtown LA - Santa Monica Via Venice Bl, 754 Hollywood - Athens Via Vermont Av, 728 Downtown LA - Century City Via West Olympic Bl, 200 Echo Park- Exposition Park Via Alvarado-Hoover Sts, 33 Downtown LA - Santa Monica Via Venice Bl, 28 Downtown LA - Century City Via West Olympic Bl, 33 Downtown LA - Santa Monica Via Venice Bl, 603 Glendale-Grand Sta Via San Fernando-Rampart-Hoover, 206 Hollywood - Athens Via Normandie Av, 28 Downtown LA - Century City Via West Olympic Bl, 33 Downtown LA - Santa Monica Via Venice Bl, 30 W Hollywood - Dtwn LA - Indiana Sta Via Pico & 1st, 33 Downtown LA - Santa Monica Via Venice Bl, <snipped by me>

I've tried using the DISTINCT function at various places but no dice. Any help would be greatly appreciated as I need to do this for several types of transportation services.

Here is the link to the map: http://arcg.is/1TaGPG in case anyone wants to putter with it.


Thank you for your time and help.

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

This is one way to do it (also sorting the route names)

var arr = [];
var count = 0;
var i = Intersects(FeatureSetById($map, /* Metro Bus Lines */ "Metro_Bus_and_Rail_102"),$feature);

for(var f in i){
 arr[count] = (f.RouteName);
 count += 1;
}

var result = Distinct(arr);
return Sort(result);

View solution in original post

3 Replies
KenBuja
MVP Esteemed Contributor

This is one way to do it (also sorting the route names)

var arr = [];
var count = 0;
var i = Intersects(FeatureSetById($map, /* Metro Bus Lines */ "Metro_Bus_and_Rail_102"),$feature);

for(var f in i){
 arr[count] = (f.RouteName);
 count += 1;
}

var result = Distinct(arr);
return Sort(result);
ClaudiaEspinosa-Villegas
Emerging Contributor

THANK YOU, it worked!!!

0 Kudos
KenBuja
MVP Esteemed Contributor

Please click the "Mark Correct" button to signify this question was answered.

0 Kudos