【ArcGIS技巧】用地块生成界址点去重、顺时针编号挂接DKBM属性

"农经权二轮延包上传到网签数据包,矢量数据不止地块矢量数据。还需要界址点、界址线等要素图层。这个数据不是很重要,但是得有,小编就写了个arxtools的工具来生成此图层,并且进行去重与编号字段、地块编码字段的生成,后续补充些字段即可,感兴趣的可以下载来使用。"

1、工具使用

在开始使用前,建议先对面要素图层进行简化,这样就防止拐点隔太近导致后续质检报错。打开arcmap,依次找到工具箱------系统工具箱------cartography tools.tbx------制图综合------简化面。(简化容差填1米)

插件界面很简单,打开工具箱脚本,输入的要素图层:1、地块图层(简化后的面要素图层),2、输出位置(选择一个文件夹目录)。注意:地块要素图层要有字段"DKBM"。

执行程序,在文件夹里会生成一个"JZD.shp"的要素图层,里面会包含字段"DKBM"、"JZDH",如果一个点属于多个地块共有,用"/"隔开。

下载后记得加载py文件,不会的参考:【ArcGIS技巧】分享个判断是否基本农田的工具。

2、代码脚本

脚本的代码分享给大家,可以在此基础上修改(写代码的过程中,在pycharm和其他python解析器都能运行,在arcmap报错,后来找了一圈是有些变量需要设置成全局变量global),有的编号会在前面加字母"J":

python 复制代码
# -*- coding: utf-8 -*-
import arcpy
import math
from collections import OrderedDict
import sys
import os
# 设置默认编码为UTF-8
reload(sys)
sys.setdefaultencoding('utf-8')
# 输入输出路径
dk_shp = arcpy.GetParameterAsText(0)
jzd_folder = arcpy.GetParameterAsText(1)
output_fc = os.path.join(jzd_folder, u"JZD.shp")
# 创建空字典存储界址点信息(使用OrderedDict保持顺序)
global point_dict1
point_dict1 = OrderedDict()
# 处理地块要素
with arcpy.da.SearchCursor(dk_shp, ["DKBM", "SHAPE@"]) as cursor:
    global point_dict1
    for row_idx, row in enumerate(cursor):
        # try:  # 添加错误处理外层
        dkbm = row[0]
        geom = row[1]
        if geom.isMultipart or geom.type != "polygon":
            arcpy.AddMessage(u'地块 {} 包含多部件或非面要素,已跳过'.format(dkbm))
            continue
        extent = geom.extent
        northwest = arcpy.Point(extent.XMin, extent.YMax)
        # 优化顶点处理逻辑
        vertices = []
        for part in geom.getPart():
            part_vertices = []
            for pnt in part:
                if pnt:
                    part_vertices.append((pnt.X, pnt.Y))
            # 移除每个part的闭合点
            if len(part_vertices) > 1 and part_vertices[-1] == part_vertices[0]:
                part_vertices.pop()
            vertices.extend(part_vertices)
        if not vertices:
            arcpy.AddMessage(dkbm)
            continue
        # 顶点有效性检查
        if vertices == []:
            arcpy.AddMessage('CUO')
            continue
        # 添加计算保护
        try:
            distances = [
                math.hypot(v[0] - northwest.X, northwest.Y - v[1])
                for v in vertices
            ]
            min_dist = min(distances)
            start_idx = distances.index(min_dist)
        except:
            arcpy.AddMessage(dkbm)
            continue
        n = len(vertices)
        ordered_indices = [(start_idx + i) % n for i in range(n)]
        if not len(ordered_indices)==len(vertices):
            arcpy.AddMessage(dkbm)
            continue
        for point_number, vertex_idx in enumerate(ordered_indices, start=1):
            raw_x,raw_y= vertices[vertex_idx]
            hashed_coord = (round(raw_x,3),round(raw_y,3))
            if hashed_coord not in point_dict1:
                point_dict1[hashed_coord] = {'point':arcpy.Point(raw_x, raw_y),'dkbms':[],'jzdhs':[]}
            current_entry = point_dict1[hashed_coord]
            if dkbm not in current_entry['dkbms']:
                current_entry['dkbms'].append(dkbm)
                current_entry['jzdhs'].append(str(point_number))
# 创建界址点要素
global sr
sr = arcpy.Describe(dk_shp).spatialReference
arcpy.CreateFeatureclass_management(jzd_folder, "JZD.shp", "POINT", spatial_reference=sr)
arcpy.AddField_management(output_fc, "DKBM", "TEXT", field_length=255)
arcpy.AddField_management(output_fc, "JZDH", "TEXT", field_length=255)
# 写入要素
with arcpy.da.InsertCursor(output_fc, ["SHAPE@", "DKBM", "JZDH"]) as cursor:
    for key in point_dict1.values():
        dkbm_str = "/".join(key['dkbms'])
        jzdh_str = "/".join(key['jzdhs'])
        cursor.insertRow((
            arcpy.PointGeometry(key['point'], sr),
            dkbm_str,
            jzdh_str
        ))
arcpy.AddMessage(u"finish")
相关推荐
非科班Java出身GISer2 小时前
ArcGIS JS 基础教程(46):编辑要素属性 FeatureForm
arcgis·arcgis js编辑要素·arcgis js 要素·arcgis js要素属性·arcgis js 编辑属性·arcgis js编辑要素属性
梅如你1 天前
ISPRS | 1990-2020年间中国人工林与天然林的空间分布数据
arcgis·gis·遥感
limit00754 天前
公开 WMTS / XYZ 瓦片接入 Cesium:6 类常见问题与排查顺序
chrome·低代码·arcgis·web3·旅游
limit00755 天前
三维模型悬空与切片偏移的排查顺序
低代码·3d·arcgis·web3·安卓·webgl
最强小杰5 天前
Continue + minimax-m3 接入教程:协议、模型 ID、404 与工具调用排错
arcgis·ai
2501_934304409 天前
新增2026年! 2012-2026年全国逐月夜间灯光数据
arcgis·gis数据
梅如你10 天前
中国2026年路网数据
arcgis·gis·遥感
梦想的初衷~10 天前
GPT × ArcGIS 强强联合:AI助力数据处理、空间分析、可视化及多案例综合应用实战教程
人工智能·gpt·arcgis
时间的情敌11 天前
《WebGIS EPSG:4326 与 EPSG:3857 墨卡托投影转换》
arcgis·mars2d
时间的情敌11 天前
《Mars2D 快速上手,从零搭建三维 GIS 项目》
arcgis·mars2d