Arcgis分割图斑编码工具

一、分割图斑编码:分割图斑在原图斑编码的基础上_1、_2................的续编。
二、代码:

# coding: utf-8
import arcpy
from collections import Counter

def get_repeat_values(in_table, field):
    fields_values = []
    with arcpy.da.SearchCursor(in_table, field) as rows:
        for row in rows:
            code = str(row[0])
            if code != "" or code != " ":
                fields_values.append(code)
    field_dict = dict(Counter(fields_values))
    result = [key for key, value in field_dict.items() if value > 1]
    return result


def coding(table, field, repeat_values):
    for value in repeat_values:
        where_cause = "{0}='{1}'".format(field, value)
        count = 1;
        with arcpy.da.UpdateCursor(table, field, where_cause) as cursor:
            for row in cursor:
                row[0] = "{0}_{1}".format(str(row[0]), str(count).rjust(1, "0"))
                cursor.updateRow(row)
                count = count + 1
fcs = arcpy.GetParameterAsText(0)
field = arcpy.GetParameterAsText(1)
repeat_values = get_repeat_values(fcs, field)
coding(fcs, field, repeat_values)

三、工具箱:
在这里插入图片描述
四、下载:

资源下载

posted @ 2023-12-11 11:23  XYSGIS  阅读(35)  评论(0编辑  收藏  举报