Select to view content in your preferred language

Calculating the mean with attribute rules and getting the error: Failed to evaluate Arcade expression

1131
2
Jump to solution
10-19-2023 12:23 AM
NadjaHertel
Occasional Contributor

Hi all, 

I have two layers. The first layer, contains streets as a line feature and in it, I make the attribute rules to extend the dataset. In my second layer, called "Analysepunkte_ExportFeatures" and that contains points that lie on those lines from the first layer. Each of the points contains a measurement value, the road width. Now I want to intersect the layers, and to calculate the mean of these points for each line. 
When I am trying to update my attribute table in a test field with the field calculator, I get the error: 

ERROR 160912: Failed to evaluate Arcade expression.

If I run everything through without this one attribute rule, then everything works again.

 

Here is my script of the attribute rule:

var fsSM = FeatureSetByName($datastore, "Analysepunkte_ExportFeatures", ["FB_Breite"]);
var zust = Intersects(fsSM, $feature);
var cnt = Count(zust)
var expr = ''

If (cnt == 0)
{expr = '0'}
else {
expr = Mean(zust)
}
return expr

 

How can I solve this?

Thanks for your help! 🙂

 

0 Kudos
1 Solution

Accepted Solutions
NadjaHertel
Occasional Contributor

@DanPatterson Thanks for your input! Your input brought me to the solution. 

Now, the script works for me - I've just needed to specify that my output needs to be a number:

var fsSM = FeatureSetByName($datastore, "Analysepunkte_ExportFeatures", ["FB_Breite"]);
var zust = Intersects(fsSM, $feature);
var cnt = Count(zust)
var expr = ''

if (cnt == 0)
{expr = '0'}
else {
expr = Number(Mean(zust, "FB_Breite"))
}
return expr

View solution in original post

0 Kudos
2 Replies
DanPatterson
MVP Esteemed Contributor

wouldn't you have to convert expr = Mean(zust) to text to match the output case of when cnt == 0 ?


... sort of retired...
0 Kudos
NadjaHertel
Occasional Contributor

@DanPatterson Thanks for your input! Your input brought me to the solution. 

Now, the script works for me - I've just needed to specify that my output needs to be a number:

var fsSM = FeatureSetByName($datastore, "Analysepunkte_ExportFeatures", ["FB_Breite"]);
var zust = Intersects(fsSM, $feature);
var cnt = Count(zust)
var expr = ''

if (cnt == 0)
{expr = '0'}
else {
expr = Number(Mean(zust, "FB_Breite"))
}
return expr

0 Kudos