Select to view content in your preferred language

Getting a null value to give a custom response in an ArcGIS Online pop-up using Arcade

1205
6
05-04-2021 01:14 PM
Labels (1)
DerekNewland
Emerging Contributor

So I have an intersect expression that  simply takes a single field I care about from a layer and includes it in the pop up of the layer on top. However, there isn't always going to be an underlying polygon when the top layer is selected. As of right now it just leaves that field blank in the pop up. I would like it to display "Not in the Renewable Energy Overlay" when there is no layer to intersect. Would I use an IF statement or an IIF or maybe an IsEmpty statement and what would the syntax be? 

My current simple intersect expression:

var Overlay =FeatureSetByName($map,"Renewable Energy Overlay");
var feature_buf=Buffer($feature, -25, 'feet');
var IntersectLayer=Intersects(Overlay, feature_buf);

for (var r in intersectLayer){
return r.EnergySour
}

All of the examples I have found deal with numbers or calculating number fields, etc. but the field in question is a text field. I am sure I am just confusing myself by way overthinking and complicating this. I'm still trying to figure out and understand how to create expressions with more than 1 function.

Thank you for any help,

Derek

0 Kudos
6 Replies
DavidPike
MVP Frequent Contributor

I think intersects return a boolean so possibly:

if (intersectLayer == True) {
for (var r in intersectLayer) {
return r.EnergySour
}
else {
return 'Not in the Renewable Energy Overlay'
}
DerekNewland
Emerging Contributor

It does not appear to like the else portion of that expression. Keeps giving me an unexpected token error. Thought it might be a missing bracket but that does not seem to fix anything.

0 Kudos
jcarlson
MVP Esteemed Contributor

It's missing a curly bracket. Put a second } before the else.

- Josh Carlson
Kendall County GIS
0 Kudos
DerekNewland
Emerging Contributor

Ah of course the 1 way I didn't place the second bracket.

Thank you

0 Kudos
jcarlson
MVP Esteemed Contributor

Count can work, too. Against a featureset, 0 indicates there are no intersected features.

if(Count(featureset) > 0){
   return 'something'
} else {
   return 'there\'s nothing here!'
}

 

I'm curious about your code, though. Is the negative buffer to ensure that you're getting a single feature returned? You could use First to grab that feature directly instead of using a for-loop. I've got an Arcade function that similarly looks at another layer, and spits out either a single attribute or a "none found" string.

// Overlay layer
var Overlay = FeatureSetByName($map,"Renewable Energy Overlay");

// Intersect w/ feature centroid, return overlay feature
var int_feat = First(Intersects(Overlay, Centroid($feature)));

// Output string if feature is present
if(IsEmpty(int_feat)){
    return 'Not in the Renewable Energy Overlay'
} else {
    return int_feat.EnergySour
}
- Josh Carlson
Kendall County GIS
DerekNewland
Emerging Contributor

The negative buffer is to deal with some data misalignment. Before the buffer I had several instances of the polygon that was being intersected not being the value showing in the pop-up due to there being a slight  overlap of an adjoining polygon from the layer to be intersected. So even though we are talking a few feet and the true intersecting polygon was the entirety of my solar project the value being defined in my pop-up was from the adjoining polygon. It seemed to be happening when the other polygon's record came before the true intersecting polygon's record in the attribute table.  The buffer just eliminated that problem until I am able to go over and clean up the errant polygons. If any of that makes sense.

Edit: I did try your expression and it appears to be working perfectly and ignoring my errant overlap issue. 

Thank you

0 Kudos