Select to view content in your preferred language

Labeling with Arcade Expression

605
8
11-14-2024 06:01 AM
ammsgis
Emerging Contributor

Hi everyone, I would like to labeling just the fields with higher value then i used the expression above:

 

IIf($feature.cota == Max($rel_curva_nivel_l.cota), $feature.cota, Null)

 

But returned the following error:

Object not found $rel_curva_nivel_l 

Could someone give me some help? Thanks in advance.

 

 

0 Kudos
8 Replies
ZachBodenner
MVP Regular Contributor
$rel_curva_nivel_l.cota

This doesn't look like a notation that Arcade would recognize. Where is this coming from?

Happy mapping,
- Zach
0 Kudos
ammsgis
Emerging Contributor

I tried to use instructions from Chatgpt.

0 Kudos
ZachBodenner
MVP Regular Contributor

This will probably change in the future, but ChatGPT got a lot of its training before there was a tremendous amount of documentation on Arcade. It's very very unreliable right now.

If I read your code correctly, you have a feature class where you want to compare two fields, "cote" and "rel_curva_nivel_l", and then make the label show whichever is the higher value?

Happy mapping,
- Zach
0 Kudos
ammsgis
Emerging Contributor

Actually the rel_curva_nivel_ is a feature class where the field "cote" exists. My intention is the expression sees the higher value in this field and only labeling this value.

0 Kudos
ZachBodenner
MVP Regular Contributor

So there are multiple features in that feature class, but only the one with the highest value should be labeled? I think you might do something like this. I haven't tested this and the syntax will depend on if you're doing this in Pro, map viewer, etc. In this case, it's in a web map:

//get all the features in your dataset
var p = featuresetbyname($map,"rel_curva_nivel_l")

// initialize an individual feature's "cota"
var c = $feature.cota

// identify the maximum value of "cota' within the entire feature class
var n = Max(p.cota)

// If the feature's "cota" is the same as the largest, return it, otherwise null
IIf(c == n, c, Null)

 

Happy mapping,
- Zach
0 Kudos
ammsgis
Emerging Contributor

Yeah, you got the logic, but there are a lot of features with high values and i just want to label thoses.

I tested here but returned this following error:

Object not found $map

My map's name called Map, so i didn't know why didn't recognize.

0 Kudos
ZachBodenner
MVP Regular Contributor

You must be working in Pro? If that's the case, you'd probably need to use the $datastore. Here's an example from an attribute rule of mine which might work in labeling. There's just so many different profiles for arcade that all behave a little differently, so you'll have to guess and check:

var trees = FeatureSetByName($datastore, "epgdb.PARKS.TreeInventory")

so this is a feature class in an enterprise geodatabase called "epgdb" in the "PARKS" schema, feature class name TreeInventory. If your data is in a file geodatabase, I believe you can notate it with the just databaseName.featureclassName

Happy mapping,
- Zach
0 Kudos
ammsgis
Emerging Contributor

I really glad for your help but now return Object not found $datastore kkk, i'll give up for while. In another moment i return to this.

Best Regards!

 

0 Kudos