Select to view content in your preferred language

Attribute Rules: Calculating the weighted mean of a line geometry

10-27-2023 03:01 AM
Labels (1)
New Contributor II

Hi all,

I am trying to calculate the weighted mean of a line geometry within the attribute rules. The lines represent a road network with different roads, and each of these roads is further divided into different parts. Each of these parts has a certain condition value, which tells in which condition this section is. Now I want to calculate the condition of the individual roads, and for this I need the weighted mean of the condition (calculated along the individual roads).

I have already tried a few things, but I can't get any further on my own. And as far as I know, there is no easier way to calculate the weighted mean than doing every single step individually. Here is the version of my last try:


\\ First I stored the different attributes on different variables and I also created empy variables:

var zust = FeatureSetByName($datastore, "Street_Conditions", ["INDEXI1"]);

var lngth = FeatureSetByName($datastore, "Street_Conditions", ["Shape_Length"]);

var expr = ''

var wght = ''

var sum_wght = ''

var sum_lngth =''



\\ Then I created a if-else statment, for my calculations in case, that there are zero-values within the different street values and calculated the individual steps of the weighted mean

if (zust == 0 || lngth == 0)

{expr = 'no value'}


wght = (zust*lngth)

sum_wght = Number(Sum(wght))

sum_lngth = Number(Sum(lngth))

expr = (sum_wght/sum_lngth)


return expr



Many thanks for your help.

0 Kudos
0 Replies