Decode(Intersects(FeatureSetByName, $feature) -Arcade PopUp

687
4
Jump to solution
11-01-2023 12:58 PM
Confetti
Occasional Contributor

I am making a popup with arcade for address points. I am running an intersect on a polygon layer and then trying to decode the variable the object is stored in (sel).

 

var z1 = 'Jimbob'
var z2 = 'Scuba Steve'
var z3 = 'Stranger'
var z4 = 'Pedestrian'
var sel = Intersects(FeatureSetByName($map, "Zones"), $feature)
return (sel)
//return(FeatureSetByName($map, "Zones"))
return Decode(sel, "BZ1", z1, "BZ2", z2, "BZ3", z3, "BZ4", z4, "Scooby")
 
When I search an address I get the default "Scooby" even though the address is clearly in one of the other code options.
 
return(sel) shows the following image:BZ3.png
0 Kudos
1 Solution

Accepted Solutions
Confetti
Occasional Contributor

The count suggestion did not work.

 

The below code gives me a match by matching the FeatureSet object of the intersect to itself-See the Decode(sel,sel, CPDT...)

var sel = Intersects(FeatureSetByName($map, "Zones"), $feature)
return Decode(sel, sel, CPDT, "CPZ3", z1, "CPZ2", z2, "CPZ3", z3, "CPZ4", z4, "Address is not in a Greenville Community Police Zone")
 
 
 
Solution: From here I transferred the objects to an array with a loop and then put the sel variable in another array. I then compared object ids.
 
for (var i in zonez) {
  Insert(arr,0,i);
}
var arr2 = []
for (var k in sel) {
  Insert(arr2,0,k)
}
return Decode(arr2[0]['OBJECTID'], arr[3]['OBJECTID'], z1, arr[1]['OBJECTID'], z3, arr[2]['OBJECTID'], z2, arr[4]['OBJECTID'], CPDT, arr[0]['OBJECTID'], z4, "Scooby")

View solution in original post

0 Kudos
4 Replies
KenBuja
MVP Esteemed Contributor

Intersects returns a FeatureSet, but you need to get the attribute from a single feature to use in your Decode statement.

var z1 = 'Jimbob'
var z2 = 'Scuba Steve'
var z3 = 'Stranger'
var z4 = 'Pedestrian'
var sel = Intersects(FeatureSetByName($map, "Zones"), $feature)
//return (sel)
//return(FeatureSetByName($map, "Zones"))
return Decode(First(sel).P_ZONE, "BZ1", z1, "BZ2", z2, "BZ3", z3, "BZ4", z4, "Scooby")

 

0 Kudos
Confetti
Occasional Contributor

I assumed that was the case, do you know by what method that is accomplished? Dot notation and bracket notation don't seem to be the way, giving error: Test execution error: Execution error - Cannot access value using a key of this type. Verify test data.

0 Kudos
KenBuja
MVP Esteemed Contributor

It might be because there are no intersecting features. Does this work?

var z1 = 'Jimbob'
var z2 = 'Scuba Steve'
var z3 = 'Stranger'
var z4 = 'Pedestrian'
var sel = Intersects(FeatureSetByName($map, "Zones"), $feature)
if (Count(sel) > 0) return Decode(First(sel).P_ZONE, "BZ1", z1, "BZ2", z2, "BZ3", z3, "BZ4", z4, "Scooby")
0 Kudos
Confetti
Occasional Contributor

The count suggestion did not work.

 

The below code gives me a match by matching the FeatureSet object of the intersect to itself-See the Decode(sel,sel, CPDT...)

var sel = Intersects(FeatureSetByName($map, "Zones"), $feature)
return Decode(sel, sel, CPDT, "CPZ3", z1, "CPZ2", z2, "CPZ3", z3, "CPZ4", z4, "Address is not in a Greenville Community Police Zone")
 
 
 
Solution: From here I transferred the objects to an array with a loop and then put the sel variable in another array. I then compared object ids.
 
for (var i in zonez) {
  Insert(arr,0,i);
}
var arr2 = []
for (var k in sel) {
  Insert(arr2,0,k)
}
return Decode(arr2[0]['OBJECTID'], arr[3]['OBJECTID'], z1, arr[1]['OBJECTID'], z3, arr[2]['OBJECTID'], z2, arr[4]['OBJECTID'], CPDT, arr[0]['OBJECTID'], z4, "Scooby")
0 Kudos