All,
I am attempting to make an Arcade expression that automatically counts up flags placed inside of a polygon. I attempted to grab the counting portion from another user but that aspect of the expression continues to fail. The intersect portion also does not seem to be working correctly. I have attached a sample code. Any suggestions/advice would be greatly appreciated! Thanks in advance.
If (IsEmpty($feature.Flag)) {
var numberlist = FeatureSetByName ($map, "Wetland")
var topnum = Top(OrderBy(numberlist, 'Flag DESC'), 1)
var counter = Number(max(topnum, 'Flag))
var Flag = counter + 1
var polygons = FeatureSetByName($map, "Boundary")
var i_polygon = First(Intersects(polygons, $feature))
if(i_polygon == null) {return null}
}
return i_polygon.Name + Flag
Assuming you are adding this calculation to your boundary layer (or the polygon layer where you want to count the flags) try this:
Thank you for your reply. I am attempting to add this calculation to the Flag feature so I can use it to automatically count the flags so numbers are not skipped. As an example, I am doing a wetland delineation in "State Park". I want the field to calculate such that every time I add a point in FieldMaps, the form looks for an intersection with the boundary layer and records that intersection and then adds a number to the end. Something like StatePark 1, StatePark 2, etc. Thank you for your assistance and apologies for the misunderstanding.
@JPWillson I haven't done any additional testing yet, but I did just notice the 'Flag' on line 4 in your expression is missing a '.
@JPWillson I did some more testing and I came up with this. You will need to make a few changes based on your data, let me know if you have any questions.
//Feature set of your park/polygon boundary
var park = FeatureSetByName($map, "Boundaries")
//Feature set of your flag layer
var flags = FeatureSetByName($map, "Flags")
//finding the nearest park/polygon, the park/polygon the point falls in
var nearestPark = First(Intersects($feature, park))
//Count of points falling in that polygon
var countFlags = Count(Intersects(flags, nearestPark))
//return the park name with a count, and adding one to the count, to account for the new point being added, if no flags, return null
If (IsEmpty(countFlags)){
return null
}else{
return nearestPark.Name + " " + (countFlags + 1)
}
Kerri,
Thank you again for assistance. I am trying to use this as an expression for a FieldMap so the wetland features are being created as one is collecting data. I would like the wetland features to be collected as a polygon. As wetland polygons are created, I would like the expression to grab the polygon from the boundaries. Then the count portion would be counting each discrete polygon as they are created. Example: Washington Park 1 would be the first wetland polygon closed in Washington Park.