Select to view content in your preferred language

Compare a value from FeatureSetByName Column w/ $feature column

531
4
10-13-2023 07:32 AM
ColtonSnelling1
Emerging Contributor

Hello all,

 

I am trying to flag any rows that contain a value greater than a column value from a different table.  Based on the code below, I am having an issue referring to the MLENGTH field.  It says a Dictionary Type is expected.

 

 

var lrsRoute = FeatureSetByName($datastore, 'RH_LRS_Routes', ['ROUTEID', 'MLENGTH'], false)
var routeID = $feature.ROUTEID

var beg_mi = $feature.BEG_MI
var end_mi = $feature.END_MI
var maxMileage = Max([beg_mi, end_mi])

var routeFilter = Filter(lrsRoute, "ROUTEID = @routeID")

IIF(maxMileage < routeFilter.MLENGTH, True, False)

 

 

 

Tags (1)
0 Kudos
4 Replies
KenBuja
MVP Esteemed Contributor

Filter returns a FeatureSet and you need the first feature in that set for your IFF function.

 

var routeFilter = First(Filter(lrsRoute, "ROUTEID = @routeID"));

 

 

 

0 Kudos
SarahRijneke
Frequent Contributor

Not sure if I 100% understand what you are trying to achieve (the filter function does not make sense to me) - I assume your end goal is to have either the value True or False written to your feature's attribute table. If so, I think your expression needs to look something more like this:

 

var lrsRoute = FeatureSetByName($datastore, 'RH_LRS_Routes', ['ROUTEID', 'MLENGTH'], false);
var maxMileage=Max($feature.BEG_MI ,$feature.END_MI);
var routeFilter = Filter(lrsRoute, "ROUTEID = @routeID");

for (var Route in routeFilter){
If (maxMileage < $feature.MLENGHT){
return ‘True’}
Else {
Return ‘False’}}

 

0 Kudos
ColtonSnelling1
Emerging Contributor

So the lrsRoute table is a live table that gets updated frequently.  It has a RouteID field and the Mlength value that I am trying to check against.

The $feature table that is grabbing BEG_MI and END_MI and ROUTEID is what I am actually trying to check.  If the maxMileage is greater than the Mlength field from the lrsRoute table, flag it as an error.

0 Kudos
SarahRijneke
Frequent Contributor

 

var lrsRoute = FeatureSetByName($datastore, 'RH_LRS_Routes', ['ROUTEID', 'MLENGTH'], false);
for (var row in lrsRoute){
var id = row.ROUTEID
var filteredRow = Filter($feature, “routeID = @id”)
for (var feat in FilteredRow){
var maxMileage=Max(feat.BEG_MI ,feat.END_MI);
If (maxMileage < feat.MLENGHT){
return “True”}
else{
return “False”}
}}

 

 

0 Kudos