Select to view content in your preferred language

Arcade: Returning names of all Counties that intersect Wildfire parimeter

1617
7
Jump to solution
07-14-2022 07:22 PM
AFackler_NAPSG
Frequent Contributor

I am trying to create a script on a wildfire boundary layer (polygon) that will return the name of every county it touches, so users can select a fire parameter and know what counties are affected. I had this working a while back and I provided what I had below, but now it returns nothing but a blank row. Any ideas? I'm not set on the expression below if there is a better solution.

var counties = FeatureSetByName($map,"USA Counties (Generalized)");
var intersectFires = Intersects(counties, $feature);
var uniqueFires = [];
for (var feat in intersectFires) {
    if (IndexOf(uniqueFires, feat) == -1){
        uniqueFires[Count(uniqueFires)] = [" " + feat.NAME];
    }
}

return uniqueFires

 

0 Kudos
3 Solutions

Accepted Solutions
jcarlson
MVP Esteemed Contributor

I would take a look at the function Push, which handles what you're doing in line 6 a bit more clearly. You could also use Distinct to remove duplicates from an array.

Also, uniqueFires here is an array. If you just want the names, Concatenate could be useful here, to.

Finally, consider using FeatureSetByPortalItem to make the connection to the county layer more explicit.

All together, it might look something like this:

// get the counties layer
var portal = Portal('https://arcgis.com')
var counties = FeatureSetByPortalItem(
    portal,
    '7566e0221e5646f99ea249a197116605',
    0,
    ['NAME']
)

// intersect feature with counties
var xs = Intersects(
    $feature,
    counties
)

// create array of intersected county names
var c_array = []

for (var c in xs){
    Push(c_array, c['NAME'])
}

// remove duplicates
var unique_counties = Distinct(c_array)

// concatenate array, return string

return Concatenate(unique_counties, ', ')

 

And here's what it looks like in action:

jcarlson_0-1657854179004.png

 

- Josh Carlson
Kendall County GIS

View solution in original post

AFackler_NAPSG
Frequent Contributor

Thanks for your response @jcarlson!

I put in the code and set up the pop-up but I'm still not seeing any of the county names. Any ideas?

AFackler_NAPSG_0-1657899441455.png

AFackler_NAPSG_1-1657899482257.png

 

View solution in original post

0 Kudos
jcarlson
MVP Esteemed Contributor

There's not a function, but the pre-Push method uses an index variable, and then incrementing it. By accessing the next item in an array by number, you can assign values to it, which will work the same way.

var idx = 0

for (var c in xs) {
    c_array[idx] = c['NAME']
    idx ++
}
- Josh Carlson
Kendall County GIS

View solution in original post

7 Replies
jcarlson
MVP Esteemed Contributor

I would take a look at the function Push, which handles what you're doing in line 6 a bit more clearly. You could also use Distinct to remove duplicates from an array.

Also, uniqueFires here is an array. If you just want the names, Concatenate could be useful here, to.

Finally, consider using FeatureSetByPortalItem to make the connection to the county layer more explicit.

All together, it might look something like this:

// get the counties layer
var portal = Portal('https://arcgis.com')
var counties = FeatureSetByPortalItem(
    portal,
    '7566e0221e5646f99ea249a197116605',
    0,
    ['NAME']
)

// intersect feature with counties
var xs = Intersects(
    $feature,
    counties
)

// create array of intersected county names
var c_array = []

for (var c in xs){
    Push(c_array, c['NAME'])
}

// remove duplicates
var unique_counties = Distinct(c_array)

// concatenate array, return string

return Concatenate(unique_counties, ', ')

 

And here's what it looks like in action:

jcarlson_0-1657854179004.png

 

- Josh Carlson
Kendall County GIS
AFackler_NAPSG
Frequent Contributor

Thanks for your response @jcarlson!

I put in the code and set up the pop-up but I'm still not seeing any of the county names. Any ideas?

AFackler_NAPSG_0-1657899441455.png

AFackler_NAPSG_1-1657899482257.png

 

0 Kudos
jcarlson
MVP Esteemed Contributor

Double check how the popup itself is configured. Are you referencing {expression/expr2} (or whatever the expression number is) in the popup text? I can't thing why else it wouldn't show up.

- Josh Carlson
Kendall County GIS
0 Kudos
AFackler_NAPSG
Frequent Contributor

Okay I got it working. I had to do the old fashioned clear the browser cache/ try in another browser and it looks like that did the trick. Thanks for your help!

0 Kudos
AileYG
by
Emerging Contributor

Very nice example! @jcarlson 

I'm trying to do something very similar with two Intersecting layers. I got it working on arcGIS pro, but then I realized I don't have the function 'Push' in our portal... 

Is there a similar function I can use instead of 'Push' ?

0 Kudos
jcarlson
MVP Esteemed Contributor

There's not a function, but the pre-Push method uses an index variable, and then incrementing it. By accessing the next item in an array by number, you can assign values to it, which will work the same way.

var idx = 0

for (var c in xs) {
    c_array[idx] = c['NAME']
    idx ++
}
- Josh Carlson
Kendall County GIS
AileYG
by
Emerging Contributor

Thanks for your quick response
It worked like a charm!

0 Kudos