当前位置: 首页 > backend >正文

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

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

1、工具使用

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

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

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

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

2、代码脚本

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

# -*- 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_dict1for 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))continueextent = geom.extentnorthwest = 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)continuen = len(vertices)ordered_indices = [(start_idx + i) % n for i in range(n)]if not len(ordered_indices)==len(vertices):arcpy.AddMessage(dkbm)continuefor 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")

http://www.xdnf.cn/news/4661.html

相关文章:

  • 四、Hadoop 2.X vs 3.X:特性、架构与性能全解析
  • 趣味编程:爱心
  • 昆仑万维财报解读:AI商业化卷王
  • CF每日5题
  • 《数据结构初阶》【链式二叉树】
  • 【时时三省】(C语言基础)怎样定义和引用二维数组
  • 数字孪生医疗:构建患者特异性数字孪生体路径探析
  • 【NLP 71、常见大模型的模型结构对比】
  • 缓存套餐-01.Spring Cache入门案例
  • 阿里云 golang 一面
  • 【开源】Python打造高效剪贴板历史管理器:实现跨平台生产力工具
  • 使用 Vite 创建 Vue 3 项目并手动配置路由的完整步骤
  • 如何通过服务主体获取 Azure 凭据
  • Ansible 流程控制
  • MySQL的索引和事务
  • @AutoConfigureBefore功能简介-笔记
  • ideal创建Springboot项目(Maven,yml)
  • 在Git历史中移除现有的Commit
  • Python 异常处理与文件 IO 操作:构建健壮的数据处理体系(3/10)
  • 高低比率策略
  • 天选5Pro(锐龙版)设备声音、显卡消失等问题完整解决记录
  • 表达式求值(算法题)
  • CMU-15445(3)——PROJECT#1-BufferPoolManager-Task#1
  • 【MySQL】存储引擎 - CSV详解
  • C++ stl中的string的相关用法
  • 【人工智能agent】--dify通过mcp协议调用工具
  • HR新战场:构建AI战略时代的认知分工与生态化人才供应链
  • 嵌入式C进阶路线指南
  • 创建虚拟服务时实现持久连接。
  • [人机交互]交互设计过程