Hi, I'm looking for help with Arcade. I have a polyline feature class of asset inventory (roads - one line for each lane, so dual carriageways will have 2 lines running paralell) and a defect feature class as points. Unfortunately the defect spatial accuracy is not great and therefore i'm unable to use the buffer and intersect function.
I am wondering if I can create a pop-up expression which counts the number of defects that match attributes within the roads inventory layer. Both layers have the unique ID field and Lane number. The road inventory has a total length, and the defect has a number of how far down the road section the defect is present, see examples below:
Road inventory:
UniqueID = abc1
LaneID = L1
Start length = 100
End length = 900
Defect Data:
UniqueID = abc1
LaneID = L1
Defect Meterage Location = 450
I would like to create a pop-up expression when i click on the road inventory layer, it can count how many defects 'fall' within the road section, by matching the attributes (UniqueID and LaneID fields), and also when there Defect Meterage location is located within the road inventory length, like this for example Defect Meterage Location (450m) is between the start and end field (StartField >='100' And EndField <='900')
Is this at all possible? If so, does anyone have any idea where to start / which function i need to use. Any help would be much appreciated
Solved! Go to Solution.
// Popup Arcade expression for the Road Inventory layer
// load the Defects layer
var defects = FeaturesetByName($datastore, "Defects", ["*"], false)
// filter the defects by UniqueID, LaneID, and Meterage
var unique_id = $feature.UniqueID
var lane_id = $feature.LaneID
var start = $feature.StartLength
var end = $feature.EndLength
var query = "UniqueID = @unique_id AND LaneID = @lane_id AND Meterage >= @start AND Meterage <= @end"
var filtered_defects = Filter(defects, query)
// create and return the text output
var return_lines = [
Count(filtered_defects) + " defects on this lane.",
]
for(var d in filtered_defects) {
Push(return_lines, "Defect at " + d.Meterage + " meters")
}
return Concatenate(return_lines, Textformatting.NewLine)
// Popup Arcade expression for the Road Inventory layer
// load the Defects layer
var defects = FeaturesetByName($datastore, "Defects", ["*"], false)
// filter the defects by UniqueID, LaneID, and Meterage
var unique_id = $feature.UniqueID
var lane_id = $feature.LaneID
var start = $feature.StartLength
var end = $feature.EndLength
var query = "UniqueID = @unique_id AND LaneID = @lane_id AND Meterage >= @start AND Meterage <= @end"
var filtered_defects = Filter(defects, query)
// create and return the text output
var return_lines = [
Count(filtered_defects) + " defects on this lane.",
]
for(var d in filtered_defects) {
Push(return_lines, "Defect at " + d.Meterage + " meters")
}
return Concatenate(return_lines, Textformatting.NewLine)
Amazing Johannes, it's worked perfectly! Thank you so much for your help
Hi Johannes, sorry another question. I've been asked to try nd symbolise the road inventory but the defect count number, so I thought about trying to run the above script in a new field and using the field calculation option, taking away the Push function element of the above code but it doesn't like it at all.
I get an error message at line 17 which falls on the var filtered_defects = Filter(defects, query)
I've tried this:
// load the Defects layer
var defects = FeatureSetByName($datastore, "Defects", ["*"], false)
// filter the defects by UniqueID, LaneID, and Meterage
var unique_id = $feature.sect_label
var lane_id = $feature.xsp_code
var start = $feature.s_chainage
var end = $feature.e_chainage
var query = "UniqueID = @unique_id AND Lane = @lane_id AND Meterage >= @start AND Meterage <= @end"
var filtered_defects = Filter(defects, query)
// create and return the text output
var return_lines = [
Count(filtered_defects)
]
return return_lines
Calculate Field expects you to return a single value, but you return an Array (the square brackets), which is a collection of multiple values. (Popup expressions also expect a single return value, I get that by using the Concatenate function)
You just have to return the count:
var filtered_defects = Filter(defects, query)
return Count(filtered_defects)
I did try that but get the same error message on line 17. Not sure what the issue is but i'll keep trying