labeling by arcade ||| etiquetar con arcade

1442
10
Jump to solution
06-07-2022 07:54 AM
Labels (1)
JavierCMartínezPrieto
Occasional Contributor

good afternoon, everyone,
I have a webmap where I represent kilometer points every meter, I would like to be able to label those P.K every 5 meters and for that I need to use an expression in arcade, but I can't find the solution.
I am currently trying a conditional with the expression equal or default but I don't get what I am looking for.
Does anyone know what would be the expression to label those P.K every 5 meters?

Thanks to all of you who participate.

example code:


if (DefaultValue($feature.cngmetros, 0))
return Pkinicial
else (DefaultValue($feature.cngmetros, 5))
return PK5metros
else (DefaultValue($feature.cngmetros, ','))
return Pk5metros
else (DefaultValue($feature.cngmetros, '.'))
return Pk5metros

Greetings Javier

#############################ESPAÑOL##########################################

 

buenas tardes a todos ,
tengo un webmap donde represento puntos kilométricos cada metro, me gustaría poder etiquetar esos P.K cada 5 metros y para ello necesito utilizar un expresión en arcade, pero no encuentro la solución.
actualmente estoy intentando un condicional con la expresion equal o default pero no consigo lo que busco.
¿alguien sabe cual seria la expresion para etiquetar esos P.K cada 5 metros?

Gracias a todos lo que participeis.

ejemplo de codigo:


if (DefaultValue($feature.cngmetros, 0))
return Pkinicial
else (DefaultValue($feature.cngmetros, 5))
return PK5metros
else (DefaultValue($feature.cngmetros, ','))
return Pk5metros
else (DefaultValue($feature.cngmetros, '.'))
return Pk5metros

Saludos Javier

Javier C. Martinez Prieto
Tags (3)
0 Kudos
4 Solutions

Accepted Solutions
RhettZufelt
MVP Frequent Contributor

Could try something using the modulus operator.  Will return the remainder of the division, so it is evenly divided by 5, will return 0.

 

if ($feature.cngmetros % 5 == 0){
    return True //(or whatever value you require)
}

 

R_

 

View solution in original post

e_mcc
by
New Contributor II

As  RhettZufelt said, calculate the remainder of the division by 5 and make your code return values only when the remainder is 0. I tried it based on RhettZufelt code:


e_mcc_0-1654734976653.png

 

e_mcc_1-1654734987294.png

 

Result: labeling only multiples of 5:

e_mcc_2-1654735027671.png

 

Cheers

E.,

 

 

View solution in original post

JavierCMartínezPrieto
Occasional Contributor

I found the solution and it was to declare the round in the return.

JavierCMartnezPrieto_1-1657696571403.png

 

result:

JavierCMartnezPrieto_2-1657696598568.png

 

thanks to all of you who participated

Javier C. Martinez Prieto

View solution in original post

0 Kudos
e_mcc
by
New Contributor II

Hi,

 

Actually, the round function does round and works fine. The label is not shown because you are returning the original value (see "return inpval") . You do the rounding in the condition statement and it dose pass the condition but it returns the original value. so, you need to modify ur code and return the rounded value

 

Cheers,

E.

 

View solution in original post

10 Replies
RhettZufelt
MVP Frequent Contributor

Could try something using the modulus operator.  Will return the remainder of the division, so it is evenly divided by 5, will return 0.

 

if ($feature.cngmetros % 5 == 0){
    return True //(or whatever value you require)
}

 

R_

 

JavierCMartínezPrieto
Occasional Contributor

thanks to both of you for the help, related to this topic how could I label the pk's ending in decimal values.

Regards

 

Javier C. Martinez Prieto
0 Kudos
e_mcc
by
New Contributor II

As  RhettZufelt said, calculate the remainder of the division by 5 and make your code return values only when the remainder is 0. I tried it based on RhettZufelt code:


e_mcc_0-1654734976653.png

 

e_mcc_1-1654734987294.png

 

Result: labeling only multiples of 5:

e_mcc_2-1654735027671.png

 

Cheers

E.,

 

 

JavierCMartínezPrieto
Occasional Contributor

thanks to both of you for the help, related to this topic how could I label the pk's ending in decimal values.

Regards

Javier C. Martinez Prieto
0 Kudos
JavierCMartínezPrieto
Occasional Contributor

I continue with this topic... I have already managed to mark the end of the P.K., but as always the arcade solutions leave much to be desired.....

JavierCMartnezPrieto_0-1657628945533.png

with this expression I have succeeded:

JavierCMartnezPrieto_1-1657629029799.png

just by looking at the image you would think that it has been achieved, but not because only 2 decimals can be shown in the P.k, so the round function would be very good, but .......

JavierCMartnezPrieto_2-1657629134786.png

 

surprise:

JavierCMartnezPrieto_3-1657629167471.png

 

disappears, the truth that I have no idea why to put a rounding disappears the value has been used the text function in case it does something but does nothing.

someone knows why this happens.

Greetings Javier

Javier C. Martinez Prieto
0 Kudos
RhettZufelt
MVP Frequent Contributor

Your parren is in the wrong place.   Looks like you need to encapsulate the round function in parens, then compare != 0.

 

 

var inpval = $feature.cngmetros
if(inpval == 0 || inpval % 5 == 0 || Round(inpval % 1 != 0,2) != 0){
    return inpval
}

 

 

R_

JavierCMartínezPrieto
Occasional Contributor

thank you for your reply.

I have tried your expression and it gives the same result, I do not understand why the round function does not round.

JavierCMartnezPrieto_0-1657696299406.png

 

Regards

Javier C. Martinez Prieto
0 Kudos
JavierCMartínezPrieto
Occasional Contributor

I found the solution and it was to declare the round in the return.

JavierCMartnezPrieto_1-1657696571403.png

 

result:

JavierCMartnezPrieto_2-1657696598568.png

 

thanks to all of you who participated

Javier C. Martinez Prieto
0 Kudos
RhettZufelt
MVP Frequent Contributor

Sorry, should have read the question better.  I just fixed the error in the round function so a label would show. 

R_