Calculate an line feature with conditional

564
5
03-09-2018 11:07 AM
FlavioFelix
New Contributor III

Hello,

I'm trying build a model to calculate a line feature with a conditional but it's not working and e it's returnig an syntax error at the expression line <return !shape.length@kilometers!/40*60>

I don't know what to do, can you guys give me a hand?

def Reclass(TIPO_PAV, CLASSIFICACAO 😞
       if (TIPO_PAV=='ASFALTO' and CLASSIFICACAO=='URBANA'):
             return 10000
        if (TIPO_PAV=='TERRA' and CLASSIFICACAO=='URBANA'):
              return 10000
        if (TIPO_PAV=='TERRA'):
               return !shape.length@kilometers! /40*60
        if (TIPO_PAV=='ASFALTO'):
               return !shape.length@kilometers!
         else:
               return 0

Tags (2)
0 Kudos
5 Replies
JamesMacKay3
Occasional Contributor

Looks like just a missing parenthesis.  Your current code:

return !shape.length@kilometers! /40)*60

Should be:

 return (!shape.length@kilometers! / 40) * 60‍‍

(I'm guessing?)

FlavioFelix
New Contributor III

Oh No !!!

Even when I fix the parenthesis it keep the same error syntax.

I'd tryied to simplify the code just writing <  return !shape.length@kilometers! > with or without parenthesis and keep returning the same error. 

any other idea ?

0 Kudos
JamesMacKay3
Occasional Contributor

If you open your Geoprocessing Results window you should see the failed calculator run.  If you expand it and view the messages, does it provide any additional information?

FlavioFelix
New Contributor III

After tryied many diferents ways to do it I've got this solution by using expression !shape.length@kilometers! in other field.

def Reclass(TIPO_PAV, CLASSIFICACAO,Distancia_Km 😞
  if TIPO_PAV=='ASFALTO' and CLASSIFICACAO=='URBANA':
     return 10000
  if TIPO_PAV=='TERRA' and CLASSIFICACAO=='URBANA':
    return 10000
  if TIPO_PAV=='TERRA':
    return Distancia_Km/40*60
  if TIPO_PAV=='ASFALTO':
    return Distancia_Km
  else:
    return "VERIFICAR"

0 Kudos
FlavioFelix
New Contributor III

Oh No !!!

Even when I fix the parenthesis it keep the same error syntax.

I'd tryied to simplify the code just writing <  return !shape.length@kilometers! > with or without parenthesis and keep returning the same error. 

any other idea ?

0 Kudos