Arcgis pro 字段计算器 python3常用方法二

发布时间:2023年12月28日

一、使用代码块简介

? ? ? ? 举例见下图

?上例:将多边形几何面积取一位小数写入【TBYBH】字段

二、常用功能块

1、按地类名称字段值,对地类代码字段赋值,代码块名称为:DLZH
? ? ? 调用表达式:DLZH(!DLMC!)
? ? ? 块代码:

def DLZH(x):
    if x==u"水田":
        return "0101"
    elif x==u"水浇地":
        return "0102"
    elif x==u"旱地":
        return "0103"
    else:
        return "非耕地"

2、按地类代码进行土地三大类分类,代码块名称为:DL3DL
? ? ? DL3DL(!DLBM!)

def DL3DL(DLFL):
    if (DLFL =="0101" or DLFL =="0102" or DLFL =="0103" ):
        return "耕地"
    elif (DLFL == "0201" or DLFL =="0202" or DLFL =="0203" or DLFL =="0204" or DLFL =="0301" or DLFL =="0301" or DLFL =="0302" or DLFL =="0303" or DLFL =="0304" or DLFL =="0305" or DLFL =="0306" or DLFL =="0307" or DLFL =="0401" or DLFL =="0402" or DLFL =="0403" or DLFL =="1006" or DLFL =="1103" or DLFL =="1104"  or DLFL =="1107" or DLFL =="1202" or DLFL =="1203"):
        return "其他农用地"
    elif (DLFL == "05H1" or DLFL == "0508" or DLFL == "0601" or DLFL == "0602" or DLFL == "0603" or DLFL == "0701" or DLFL == "0702" or DLFL == "08H1" or DLFL == "08H2" or DLFL == "0809" or DLFL == "0810" or DLFL == "09" or DLFL == "1001" or DLFL == "1002" or DLFL == "1003" or DLFL == "1004" or DLFL == "1005" or DLFL == "1007" or DLFL == "1008" or DLFL == "1009" or DLFL == "1109" or DLFL == "1201"):
        return "建设用地"
    elif (DLFL == "0404" or DLFL == "1101" or DLFL == "1102" or DLFL == "1105" or DLFL == "1106" or DLFL == "1108" or DLFL == "1110" or DLFL == "1204" or DLFL == "1205" or DLFL == "1206" or DLFL == "1207"):
        return "未利用土地"
    else:
        return "没有对应关系地类"

3、计算某要素中的折点数。代码块名称为:getVertexCount

调用表达式:getVertexCount(!shape!)

def getVertexCount(feat):    
    partnum = 0
    partcount = feat.partCount
    pntcount = 0
    while partnum < partcount:
        part = feat.getPart(partnum)
        pnt = part.next()
        while pnt:
            pntcount += 1   
            pnt = part.next()
            if not pnt: 
                pnt = part.next()
        partnum += 1
    return pntcount

4、根据某间隔值计算顺序 ID 或数字,代码块名称:autoIncrement
表达式:autoIncrement(10, 5)? ? ?,调用初始值为10,每次递增5

rec = 0
def autoIncrement(start=1, interval=1):
    global rec
    if rec == 0:
        rec = start
    else:
        rec += interval
    return rec

文章来源:https://blog.csdn.net/xa13850869/article/details/135161293
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。