Arcade if/or/default statements

1070
10
Jump to solution
02-25-2021 06:24 AM
Labels (2)
aroininen
New Contributor III

Hello community,

I am having a problem adding a logical function into an arcade state I have scraped together from the web. I am not a programmer more of a edit existing code kind of person. I will try to keep this simple.

Here is the expression I have that intersects features and provides results for what its within - landuse info

var intersectLayer =Intersects(FeatureSetByName($map,"LandUse - h Provision Overlay"), Buffer($feature, -10, 'feet'))

var Hazard = "";

for (var f in intersectLayer) {
if (Hazard == "") {
Hazard = f.NAME
} else {
Hazard += " And " + f.NAME;}}

return Hazard

the result is this:

aroininen_1-1614262634335.png

I don't know how to insert a logical function into this expression so empty values display "n/a"

I have tried: IIf , IsEmpty, DefaultValue all kinds I just don't know how to fit them in

any help would be greatly appreciated!!!

Thanks

Aaron

 

also, can someone explained what the word hazard is for? it was just with the code so I left it in!

thanks again

 

 

 

 

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Regular Contributor

Ah, I think I misunderstood your original question...

Does this do what you want?

// Get all features of the LandUse layer that are intersected by the selected feature.
// You apply a negative buffer here, so you don't get land use features that only intersect with the outer edges, is that correct?
var intersect_layer = Intersects(FeatureSetByName($map, "LandUse - h Provision Overlay"), Buffer($feature, -10, 'feet'))

// No intersecting features found -> "n/a"
if(Count(intersect_layer) == 0) {
  return "n/a"
}

// Define and initialize the variable that stores your text
var intersected_land_uses = ""

// Loop through the intersecting land use features
for (var f in intersect_layer ) {
  var land_use = IIF(IsEmpty(f.NAME), "n/a", f.NAME)
  if (intersected_land_uses == "") { // there is nothing in here yet
    intersected_land_uses = land_use
  } else { // there is something in here already, append with " And "
    intersected_land_uses += " And " + land_use
  }
}
return intersected_land_uses

 


Have a great day!
Johannes

View solution in original post

10 Replies
JohannesLindner
MVP Regular Contributor

"Hazard" is the name of the variable that stores your text. You can call it pretty much anything you want, though descriptive names are the most sensible.

 

 

// Get all features of the LandUse layer that are intersected by the selected feature.
// You apply a negative buffer here, so you don't get land use features that only intersect with the outer edges, is that correct?
var intersect_layer = Intersects(FeatureSetByName($map, "LandUse - h Provision Overlay"), Buffer($feature, -10, 'feet'))

// Define and initialize the variable that stores your text
var intersected_land_uses = ""

// Loop through the intersecting land use features
for (var f in intersect_layer ) {
  var land_use = IIF(IsEmpty(f.NAME), "n/a", f.NAME)
  if (intersected_land_uses == "") { // there is nothing in here yet
    intersected_land_uses = land_use
  } else { // there is something in here already, append with " And "
    intersected_land_uses += " And " + land_use
  }
}
return intersected_land_uses

 

 

 


Have a great day!
Johannes
0 Kudos
aroininen
New Contributor III

wow! thanks!!!

I tried it but it won't display n/a.... am I missing something?

thanks again for your time - very much appreciated

intersect (pink is 'h overlay')

aroininen_0-1614274255167.png

no intersect

aroininen_1-1614274308541.png

 

0 Kudos
JohannesLindner
MVP Regular Contributor

So where it says "Hazard", it should say "n/a", right? Or is "Hazard" a land use?

Can you post the code you used, please?


Have a great day!
Johannes
0 Kudos
aroininen
New Contributor III

Hello!

No I want it to show n/a after 'h Overlay"  as it is outside of zone

Thanks

aroininen_0-1614693246413.png

 

0 Kudos
JohannesLindner
MVP Regular Contributor

Ah, I think I misunderstood your original question...

Does this do what you want?

// Get all features of the LandUse layer that are intersected by the selected feature.
// You apply a negative buffer here, so you don't get land use features that only intersect with the outer edges, is that correct?
var intersect_layer = Intersects(FeatureSetByName($map, "LandUse - h Provision Overlay"), Buffer($feature, -10, 'feet'))

// No intersecting features found -> "n/a"
if(Count(intersect_layer) == 0) {
  return "n/a"
}

// Define and initialize the variable that stores your text
var intersected_land_uses = ""

// Loop through the intersecting land use features
for (var f in intersect_layer ) {
  var land_use = IIF(IsEmpty(f.NAME), "n/a", f.NAME)
  if (intersected_land_uses == "") { // there is nothing in here yet
    intersected_land_uses = land_use
  } else { // there is something in here already, append with " And "
    intersected_land_uses += " And " + land_use
  }
}
return intersected_land_uses

 


Have a great day!
Johannes
aroininen
New Contributor III

thanks again for you help but I get this error

Execution Error:Invalid Parameters for Count....?

0 Kudos
aroininen
New Contributor III

could I use "Touches' instead of "intersect...?

0 Kudos
JohannesLindner
MVP Regular Contributor

Intersects and Touches both have pictures indicating what will be selected. Based on your screenshots above, your "h overlay" layer intersects your parcels, so you probably should use Intersects.

 

I don't know what's wrong with the code, it works for me. Maybe someone else can help? @DanPatterson , @JoeBorgione ?


Have a great day!
Johannes
0 Kudos
aroininen
New Contributor III

Thanks!!! I will keep playing with my code!!

Cheers

Aaron

0 Kudos