0

I have an attribute table with a lot of lines.

I want to classify them considering their length:

  • SHORT (from 0 to 50)
  • MEDIUM (from 50 to 150)
  • LONG (from 150 to 180)

How can I do avoiding to modify manually every 391 row?

Table

This does not work:

Reclass(!Lenght!)

Code Block:
def Reclass(Lenght):
    if Lenght>= 0 and Lenght<= 30
        return "Short"
    elif Lenght> 30 and Lenght<= 90):
        return "Medium"
    elif Lenght> 90 and Lenght<= 180):
        return "Long"
    elif Lenght> 30):
        return "VeryLong"

enter image description here

enter image description here

Tried with

def lenght_cat(length,lenght_cat):
      if lenght> 0 and lenght< 14:
        return (length_cat*short)
      elif lenght> 14 and lenght< 20:
        return (length_cat*long)
      else:
        return None

but does not work unfortunately.

  • Use Field Calculator. See the example: "Calculate fields using logic with Python" in Calculate Field examples. – BERA Mar 27 '19 at 9:32
  • You appear to be using Python syntax with the VB Script parser. – PolyGeo Mar 27 '19 at 10:01
  • Have a look at this gis.stackexchange.com/questions/316601/…, it should help you to properly set the field calculator – J.R Mar 27 '19 at 10:04
  • There are multiple things wrong: your field calculator appears to be for another dataset, there is no test field in your attribute table, you must tick on show codebock and place your code in there, the syntax makes no sense in your code, what are short and long where do they come from? Your first code example is about reclassifying whilst your second appears to be computing a new value for a non existent field! Finally in your reclass() function you have a closing ) but where is the opening (? That's basic maths you start and end () and your coding is not doing this. Read the help file. – Hornbydd Mar 28 '19 at 10:12