当前位置:网站首页>ArcGIS: field assignment_ The attribute table field calculator assigns values to fields based on conditions

ArcGIS: field assignment_ The attribute table field calculator assigns values to fields based on conditions

2022-07-07 23:12:00 BetterQ.

When the ArcGIS When assigning values to fields in the attribute table of the data loaded in , You can click on the “ Start editing ” Then assign values to fields manually , But when the amount of data is large, you need to use Python To assign a value to it .

After opening the property sheet , Click on the field to be assigned , Right click to select “ Field calculator ”, Here's the picture :
 Insert picture description here

Direct unified assignment :
Directly enter numbers or letters or text in the input box to assign a unified value to this field .
 Insert picture description here
.
.
Assignment by condition :
When conditional assignment is required , You can enter the following script to :
 Insert picture description here
.

def cal(f)
   if f=='s':
       return 1
   if f=='a':
       return 2
   else:
       return 99

If you need to assign a value to the field according to the size of the value, you can enter the following code :

def cal(f)
   if f>50:
       return 1
   if f<100 and f>60:
       return 2
   else:
       return 99

Be careful :
1、 Because of the use of python To write , So pay special attention to spaces and alignment , Generally indented 4 individual /8 A space , But sometimes it is 3 individual /7 A space . Problems usually occur because the space is indented incorrectly .

2、 When using words , It needs to be transcoded , To utf-8 The format can be recognized , as follows :

def cal(f)
   if f==(' The grass '.decode(utf-8)):
       return 1
   if f==(' Woodland '.decode(utf-8)):
       return 2
   else:
       return ' other '.decode(utf-8)

3、 Don't forget it if Add a colon to the back , And all are colons in English .

原网站

版权声明
本文为[BetterQ.]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071956159242.html