Skip to main content
edited title
Link
PolyGeo
  • 65.5k
  • 29
  • 115
  • 352

Calculate Using ArcGIS Field Calculator to create classes in new field more wisely?

I first classified firstColfirstCol into groups and then I want to give the groups with different weighted values in another field, SecondColSecondCol. I will need to give different weighted values very often. I find it very time-consuming whenever I modify the weighted values in my script.

I use the following script to calculate the SecondColSecondCol:

def TextValue( gridcode):
if gridcode <= 5:
    return 1
elif  5 < gridcode <= 15:
    return 2
elif  15 < gridcode <= 30:
    return 3
elif  30 < gridcode <= 40:
    return 4
elif  40 < gridcode <= 55:
    return 5
elif  55 < gridcode <= 100:
    return 6
elif  100 < gridcode :
    return 7
else:
    return "N/A"

TextValue( !firstCol! )
def TextValue(gridcode):
if gridcode <= 5:
    return 1
elif  5 < gridcode <= 15:
    return 2
elif  15 < gridcode <= 30:
    return 3
elif  30 < gridcode <= 40:
    return 4
elif  40 < gridcode <= 55:
    return 5
elif  55 < gridcode <= 100:
    return 6
elif  100 < gridcode :
    return 7
else:
    return "N/A"

TextValue( !firstCol! )

As you can see, I give the weighted value as below:

(weighted values , group).

1 = group "firstCol < 5"

2 = group "firstCol = 5 - 15"

3 = group "firstCol = 15 - 30"

4 = group "firstCol = 30 - 40

5 = group "firstCol = 40 - 55"

6 = group "firstCol = 55 - 100"

7 = group "firstCol > 100"

(weighted values  ,  group).

1   =   group "firstCol  < 5"    
2   =   group "firstCol = 5 - 15"    
3   =   group "firstCol = 15 - 30"    
4   =   group "firstCol = 30 - 40" 
5   =   group "firstCol = 40 - 55"    
6   =   group "firstCol = 55 - 100"    
7   =   group "firstCol > 100"
61  =    group "firstCol  < 5"

8   =   group "firstCol = 5 - 15"

88  =   group "firstCol = 15 - 30"

70  =   group "firstCol = 30 - 40

52  =   group "firstCol = 40 - 55"

2   =   group "firstCol = 55 - 100"

6   =   group "firstCol > 100"
    
def TextValue( gridcode):
if ...
...
else...

TextValue( !firstCol! )
61  =   group "firstCol  < 5"   
8   =   group "firstCol = 5 - 15"    
88  =   group "firstCol = 15 - 30"    
70  =   group "firstCol = 30 - 40"   
52  =   group "firstCol = 40 - 55"    
2   =   group "firstCol = 55 - 100"    
6   =   group "firstCol > 100"
    
def TextValue( gridcode):
if ...
...
else...

TextValue( !firstCol! )

Then, the script will use the new values, instead of me modifying it in the TextValueTextValue.

I first classified firstCol into groups and then I want to give the groups with different weighted values in another field, SecondCol. I will need to give different weighted values very often. I find it very time-consuming whenever I modify the weighted values in my script.

I use the following script to calculate the SecondCol:

def TextValue( gridcode):
if gridcode <= 5:
    return 1
elif  5 < gridcode <= 15:
    return 2
elif  15 < gridcode <= 30:
    return 3
elif  30 < gridcode <= 40:
    return 4
elif  40 < gridcode <= 55:
    return 5
elif  55 < gridcode <= 100:
    return 6
elif  100 < gridcode :
    return 7
else:
    return "N/A"

TextValue( !firstCol! )

As you can see, I give the weighted value as below:

(weighted values , group).

1 = group "firstCol < 5"

2 = group "firstCol = 5 - 15"

3 = group "firstCol = 15 - 30"

4 = group "firstCol = 30 - 40

5 = group "firstCol = 40 - 55"

6 = group "firstCol = 55 - 100"

7 = group "firstCol > 100"

61  =    group "firstCol  < 5"

8   =   group "firstCol = 5 - 15"

88  =   group "firstCol = 15 - 30"

70  =   group "firstCol = 30 - 40

52  =   group "firstCol = 40 - 55"

2   =   group "firstCol = 55 - 100"

6   =   group "firstCol > 100"
    
def TextValue( gridcode):
if ...
...
else...

TextValue( !firstCol! )

Then, the script will use the new values, instead of me modifying it in the TextValue.

I first classified firstCol into groups and then I want to give the groups with different weighted values in another field, SecondCol. I will need to give different weighted values very often. I find it very time-consuming whenever I modify the weighted values in my script.

I use the following script to calculate the SecondCol:

def TextValue(gridcode):
if gridcode <= 5:
    return 1
elif  5 < gridcode <= 15:
    return 2
elif  15 < gridcode <= 30:
    return 3
elif  30 < gridcode <= 40:
    return 4
elif  40 < gridcode <= 55:
    return 5
elif  55 < gridcode <= 100:
    return 6
elif  100 < gridcode :
    return 7
else:
    return "N/A"

TextValue( !firstCol! )

As you can see, I give the weighted value as below:

(weighted values  ,  group).

1   =   group "firstCol  < 5"    
2   =   group "firstCol = 5 - 15"    
3   =   group "firstCol = 15 - 30"    
4   =   group "firstCol = 30 - 40" 
5   =   group "firstCol = 40 - 55"    
6   =   group "firstCol = 55 - 100"    
7   =   group "firstCol > 100"
61  =   group "firstCol  < 5"   
8   =   group "firstCol = 5 - 15"    
88  =   group "firstCol = 15 - 30"    
70  =   group "firstCol = 30 - 40"   
52  =   group "firstCol = 40 - 55"    
2   =   group "firstCol = 55 - 100"    
6   =   group "firstCol > 100"
    
def TextValue( gridcode):
if ...
...
else...

TextValue( !firstCol! )

Then, the script will use the new values, instead of me modifying it in the TextValue.

added 382 characters in body
Source Link
NewHere
  • 141
  • 1
  • 1
  • 10

I need to classify a field, called "firstCol(double)",first classified firstCol into groups and then I want to give classifiedthe groups with different weighted values in another field, called "SecondCol(short)", withSecondCol. I will need to give different new classifiedweighted values very often. Nevertheless, giving new classified values has been aI find it very time-consuming stuff and alsowhenever I may have typos when modifyingmodify the weighted values in my script.


My column looks like this:

enter image description here

I use the following script to calculate the SecondCol:

def TextValue( gridcode):
if gridcode <= 5:
    return 1
elif  5 < gridcode <= 15:
    return 2
elif  15 < gridcode <= 30:
    return 3
elif  30 < gridcode <= 40:
    return 4
elif  40 < gridcode <= 55:
    return 5
elif  55 < gridcode <= 100:
    return 6
elif  100 < gridcode :
    return 7
else:
    return "N/A"

TextValue( !firstCol! )

As you can see, I give the classifiedweighted value as below:

(weighted values , group).

1 = < 5 group "firstCol < 5"

2 = 5 group "firstCol = 5 - 1515"

3 = 15 group "firstCol = 15 - 3030"

4 = 30 group "firstCol = 30 - 40

5 = 40 group "firstCol = 40 - 5555"

6 = 55 group "firstCol = 55 - 100100"

7 = > 100 group "firstCol > 100"


I wonder if there is a better way to give the new classified valueweighted values more efficiently. Like, just give a new column in the beginning of the script.

161  =    group "firstCol  < 5"
2
38   =   group "firstCol = 5 - 15"
4
588  =   group "firstCol = 15 - 30"

70  =   group "firstCol = 30 - 40

52  =   group "firstCol = 40 - 55"

2   =   group "firstCol = 55 - 100"

6   =   group "firstCol > 100"
    
def TextValue( gridcode):
if ...
...
else...

TextValue( !firstCol! )

Then, the script will use the new values, instead of me modifying it in the TextValue.

I need to classify a field, called "firstCol(double)", and give classified values in another field, called "SecondCol(short)", with different new classified values very often. Nevertheless, giving new classified values has been a time-consuming stuff and also I may have typos when modifying the script.


My column looks like this:

enter image description here

I use the following script to calculate the SecondCol:

def TextValue( gridcode):
if gridcode <= 5:
    return 1
elif  5 < gridcode <= 15:
    return 2
elif  15 < gridcode <= 30:
    return 3
elif  30 < gridcode <= 40:
    return 4
elif  40 < gridcode <= 55:
    return 5
elif  55 < gridcode <= 100:
    return 6
elif  100 < gridcode :
    return 7
else:
    return "N/A"

TextValue( !firstCol! )

As you can see, I give the classified value as below:

1 = < 5

2 = 5 - 15

3 = 15 - 30

4 = 30 - 40

5 = 40 - 55

6 = 55 - 100

7 = > 100


I wonder if there is a better way to give the new classified value more efficiently. Like, just give a new column in the beginning of the script.

1
2
3
4
5
6

def TextValue( gridcode):
if ...
...
else...

TextValue( !firstCol! )

Then, the script will use the new values, instead of me modifying it in the TextValue.

I first classified firstCol into groups and then I want to give the groups with different weighted values in another field, SecondCol. I will need to give different weighted values very often. I find it very time-consuming whenever I modify the weighted values in my script.


My column looks like this:

enter image description here

I use the following script to calculate the SecondCol:

def TextValue( gridcode):
if gridcode <= 5:
    return 1
elif  5 < gridcode <= 15:
    return 2
elif  15 < gridcode <= 30:
    return 3
elif  30 < gridcode <= 40:
    return 4
elif  40 < gridcode <= 55:
    return 5
elif  55 < gridcode <= 100:
    return 6
elif  100 < gridcode :
    return 7
else:
    return "N/A"

TextValue( !firstCol! )

As you can see, I give the weighted value as below:

(weighted values , group).

1 = group "firstCol < 5"

2 = group "firstCol = 5 - 15"

3 = group "firstCol = 15 - 30"

4 = group "firstCol = 30 - 40

5 = group "firstCol = 40 - 55"

6 = group "firstCol = 55 - 100"

7 = group "firstCol > 100"


I wonder if there is a better way to give new weighted values more efficiently. Like, just give a new column in the beginning of the script.

61  =    group "firstCol  < 5"

8   =   group "firstCol = 5 - 15"

88  =   group "firstCol = 15 - 30"

70  =   group "firstCol = 30 - 40

52  =   group "firstCol = 40 - 55"

2   =   group "firstCol = 55 - 100"

6   =   group "firstCol > 100"
    
def TextValue( gridcode):
if ...
...
else...

TextValue( !firstCol! )

Then, the script will use the new values, instead of me modifying it in the TextValue.

Removed unnecessary thanks etc
Source Link
PolyGeo
  • 65.5k
  • 29
  • 115
  • 352
Loading
Source Link
NewHere
  • 141
  • 1
  • 1
  • 10
Loading