Select to view content in your preferred language

Filter a featureset by attribute in arcade when in attribute rule

4219
2
Jump to solution
03-03-2023 12:45 PM
GarySpenst
Emerging Contributor

Hello, 

I am trying to make an attribute rule that calculates the length of Water Pipe within a polygon. I have had some success with  this arcade code:

var WatPipe=featuresetbyname($datastore,'WAT_Pipe',['*'])

Var Pipewithin=contains($feature,WatPipe)
return sum(length(Pipewithin))

 

After getting this to work, I realized it was grabbing all the water pipes contained in the polygon which included the abandoned and removed water pipes.

 

Is there away to filter the feature set first? I tried this and didnt have any luck

var WatPipe=filter(featuresetbyname($datastore,'WAT_Pipes',['*']),'status= in service')
var Pipewithin=contains($feature,WatPipe)
return sum(length(Pipewithin))

 

Please help

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

the filter statement in the Filter() function has to be a valid SQL statement.

You're using "status = in service", which is invalid, because status seems to be a text field, so the text value should be enclosed in single quotes.

You shouldn't need to call Sum(). Length(featureset) already returns a single numeric value.

Try this:

var WatPipe = Filter(FeaturesetByName($datastore, 'WAT_Pipes', ['*']), "status = 'in service'")
var Pipewithin = Contains($feature, WatPipe)
return Length(Pipewithin)

 

 


Have a great day!
Johannes

View solution in original post

2 Replies
JohannesLindner
MVP Frequent Contributor

the filter statement in the Filter() function has to be a valid SQL statement.

You're using "status = in service", which is invalid, because status seems to be a text field, so the text value should be enclosed in single quotes.

You shouldn't need to call Sum(). Length(featureset) already returns a single numeric value.

Try this:

var WatPipe = Filter(FeaturesetByName($datastore, 'WAT_Pipes', ['*']), "status = 'in service'")
var Pipewithin = Contains($feature, WatPipe)
return Length(Pipewithin)

 

 


Have a great day!
Johannes
GarySpenst
Emerging Contributor

Thanks that worked!!

 

0 Kudos