Designing a survey using Field maps, need to calculate a value for hazard_rating.
Which is a combination of failure_potential, size_of_part, target_rating
I'm using arcade to do this automatically to safe user interaction.
In Arcade this is what I have put together.
Sum(features_, "$feature.failure_potential"_)
Sum(features_, "$feature.size_of_part"_)
Sum(features_, "$feature.target_rating"_)
var $originalFeature.hazard_rating
I need to add up the 3 layers. They are saved as a string. Would this cause the issue?
Test execution error: ',' expected.. Verify test data.
Solved! Go to Solution.
@ChristopherCounsell Thanks for responding, I think this is what you were suggesting. I certainly need to go on an Arcade Course.....
Assuming you are calling upon a layer (featureset) and the fields are numeric:
var myfeatures = FeatureSetByName($map, "Layer Name")
var sum1 = Sum(myfeatures , "failure_potential")
var sum2 = Sum(myfeatures ,"size_of_part")
var sum3 = Sum(myfeatures ,"target_rating")
return sum1 + sum2 + sum3.
However this won't work as you indicated the fields are string. You'd need to convert each field value to numeric value to summarize them.
var myfeatures = FeatureSetByName($map, "Layer Name")
var sumValues = 0;
for (var tree in myFeatures){
sumValues += Number(tree.failure_potential) + Number(tree.size_of_part) + Number(tree.target_rating)
}
return sumValues
This would be pretty slow if your layer is large as it goes through the features one by one. Plus you are prone to errors if values are missing or non-numeric. I'd be rethinking the approach at that stage.
If you just want to return the values of the 3 string fields in the one feature, much easier:
Number($feature.field1) +Number($feature.field2) + Number($feature.field3)
I'm not sure why you have $originalFeature in there. That's for retaining existing values.
@ChristopherCounsell
I am using for my 3 fields a combo box, 1st is the label then what value I would like it to be, see from my example below.
I have used the codes:
var myfeatures = FeatureSetByName($map, "Layer Name")
var sum1 = Sum(myfeatures , "failure_potential")
var sum2 = Sum(myfeatures ,"size_of_part")
var sum3 = Sum(myfeatures ,"target_rating")
return sum1 + sum2 + sum3.
It doesn't throw me back a value, irrelevant of what values I put in for:
failure_potential
size_of_part
target_rating
No 100% sure where I am going wrong... The values are integers... That's a good start.
To be honest this information is going to be very small....
I appreciate you coming back to me..
Many thanks
Matt
@ChristopherCounsell Thanks for responding, I think this is what you were suggesting. I certainly need to go on an Arcade Course.....