I have a Parcel layer that includes zoning and a related table of zoning conditions. I would like to add the count of zoning conditions and the conditions to my parcel layer popup. I'm not sure where to start, any help would be appreciated.
It depends on how your layers are set up, but I like to use FeatureSetByPortalItem, as it is not dependent upon the second layer (in this case, zoning) actually being in the map.
Getting the count is simple enough, but getting the "conditions", which I assume means a list of the unique zoning types, is somewhat more complex, but still doable.
var yourPortal = Portal('your-portal-url') // This can be your org's AGOL url, too.
var zoning = FeatureSetByPortalItem(yourPortal, 'item-id-of-zoning-layer', 0)
var zones = Intersects($feature, zoning)
// Will grab any zoning shape which intersects with the given parcel, so alignment is critical.
return Count(zones)
// Returns the length of the 'zones' array, being the number of zoning features intersected.
As noted in the code, your alignment between layers will significantly impact the number of features returned by Intersects. In order to avoid false positives, it may be advisable to call "Buffer($feature, -5)" instead of "$feature", but test things out and see what results you get.
Works the similarly to the code above, but uses the "zones" FeatureSet to assemble an output array.
var yourPortal = Portal('your-portal-url')
var zoning = FeatureSetByPortalItem(yourPortal, 'item-id-of-zoning-layer', 0)
var zones = Intersects($feature, zoning)
var zone_array = []
var zone_index = 0
for(var z in zones){
zone_array[zone_index] = z.zoning_condition_field
// Adds the zoning condition of the given intersected feature to the zone_array object at the position zone_index
++ zone_index
// Ensures that if there are more than one zoning conditions, the next value is added at the next position in the list, otherwise the previous value would simple be overwritten
}
return zone_array
We use something like this to grab a parcel's intersected Flood Zones from FEMA's Flood Hazard Layer.
Of course, should you want the output array formatted a little more nicely, you could easily adjust your Arcade code to do that as well.
// Zones array
var z_arr = []
var z_ind = Number('0')
// Intersect feature and flood zones
var zones = Intersects($feature, FeatureSetByName($map,"USA Flood Hazard Areas"))
for (var z in zones){
var zone = z.FLD_ZONE
if (find(zone, z_arr)== -1){
// Only appends new value if it is not currently found in the index, i.e., no duplicates.
z_arr[z_ind] = zone
++z_ind
}
}
var out_str = Count(z_arr) + ' Floodway Zones:'
// Includes count in same expression as a "heading" to the list.
for (var n in z_arr){
out_str += '\n' + z_arr[n]
}
return out_str
So as you can see, it's not that complicated, but does require some more advanced Arcade.
This was a very helpful post, Josh. Thank you for taking the time to post those examples.
Thank you for your help Josh, I forgot to come back in here and tell you that this worked perfectly!