Select to view content in your preferred language

Adding values of layers to calculate a final value

326
3
Jump to solution
10-30-2024 07:09 AM
MattSully
Occasional Contributor

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.

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
MattSully
Occasional Contributor

@ChristopherCounsell   Thanks for responding, I think this is what you were suggesting.  I certainly need to go on an Arcade Course.....

$feature["failure_potential"] + $feature["size_of_part"] + $feature["target_rating"]

This works exactly what we need.

Thanks again, I'm a happy bunny now. 🙂



View solution in original post

0 Kudos
3 Replies
ChristopherCounsell
MVP Regular Contributor

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.

0 Kudos
MattSully
Occasional Contributor

@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.

MattSully_0-1730988693575.png

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

0 Kudos
MattSully
Occasional Contributor

@ChristopherCounsell   Thanks for responding, I think this is what you were suggesting.  I certainly need to go on an Arcade Course.....

$feature["failure_potential"] + $feature["size_of_part"] + $feature["target_rating"]

This works exactly what we need.

Thanks again, I'm a happy bunny now. 🙂



0 Kudos