ArcGIS 一段Python调试

文摘   2024-11-08 07:55   云南  

#coding: UTF-8

import arcpy
def  getdl(mc):
    fc = "dlcode.mdb/ghcode"
    fields = ['code']
    # For each row, print the WELL_ID and WELL_TYPE fields, and
    # the feature's x,y coordinates
    with arcpy.da.SearchCursor(fc, fields,"name='"+mc+"'") as cursor:
        for row in cursor:
            return row[0]
    return  ""


# input_poly="C:\Users\Administrator\Documents\ArcGIS\Default.gdb\中心镇区用地布局_XH11_Erase"
input_poly = arcpy.GetParameterAsText(0)
dlmc = arcpy.GetParameterAsText(1)
# dlbm=arcpy.GetParameterAsText(2)
# arcpy.AddMessage(field)
#arcpy.AddField_management(input_poly, "bm1", "TEXT", "", "", 255, "一级编码")
#arcpy.AddField_management(input_poly, "bm2", "TEXT", "", "", 255, "二级编码")
#arcpy.AddField_management(input_poly, "bm3", "TEXT", "", "", 255, "三级编码")
#arcpy.AddField_management(input_poly, "mc1", "TEXT", "", "", 255, "一级名称")
#arcpy.AddField_management(input_poly, "mc2", "TEXT", "", "", 255, "二级名称")
#arcpy.AddField_management(input_poly, "mc3", "TEXT", "", "", 255, "三级名称")


cursor = arcpy.UpdateCursor(input_poly)
for row in cursor:
    dlmctemp = row.getValue(dlmc)
    row.setValue("GHDLBM", getdl(dlmctemp))
    arcpy.AddMessage(dlmctemp)
    cursor.updateRow(row)
del cursor

GISAI
ArcGIS培训和二次开发
 最新文章