ArcGIS Pro脚本工具(16)——要素类转txt坐标文件
创始人
2024-05-09 00:11:30
0

之前介绍过txt坐标文件如何转为GIS要素类

ArcGIS Pro脚本工具(8)——txt坐标文件转shp_学学GIS的博客-CSDN博客_txt转shp国土部门给过来的数据经常需要转换,比如土地报批和高标准农田的数据经常给一个txt文件过来,不能直接在GIS软件中使用。这些txt文件结构通常如下。如果txt文件的数据量小,那么在Excel中预处理再在ArcGIS中使用工具生成面还算简单。如果面的个数很多,那用Excel预处理这一步就很繁琐了。之前已经接触过Python以及ArcPy,估计可以使用编程的方法解决。在一番面向百度编程之后,终于找到一个堪称完美的解决办法。在此也感谢一下趟水的前辈。arcgis 经纬度转大地坐标_土地报备坐标txthttps://blog.csdn.net/baidu_28157641/article/details/122811245网友反馈希望做一个相反功能的工具,也就是从要素类转为txt坐标文件,虽然自己的工作基本没碰到这个需求,不过还是尝试制作了一下。

下面演示将变更数据内的几块用地转为txt坐标文件。

工具演示

工具脚本

import arcpyinfc = arcpy.GetParameterAsText(0)
txtPath = arcpy.GetParameterAsText(1)f = open(txtPath, 'w')f.write("[属性描述]\n")
f.write("格式版本号=" + arcpy.GetParameterAsText(3) + "\n")
f.write("数据生产单位=" + arcpy.GetParameterAsText(4) + "\n")
f.write("数据生产日期=" + arcpy.GetParameterAsText(5) + "\n")
f.write("坐标系=" + arcpy.GetParameterAsText(6) + "\n")
f.write("几度分带=" + arcpy.GetParameterAsText(7) + "\n")
f.write("投影类型=" + arcpy.GetParameterAsText(8) + "\n")
f.write("计量单位=" + arcpy.GetParameterAsText(9) + "\n")
f.write("带号=" + arcpy.GetParameterAsText(10) + "\n")
f.write("精度=" + arcpy.GetParameterAsText(11) + "\n")
f.write("转换参数=" + arcpy.GetParameterAsText(12) + "\n")
f.write("[地块坐标]\n")fidVaule = arcpy.GetParameterAsText(2)
fidName = fidVaule.split(";")
fidList = ["OID@", "SHAPE@"]
for fid in fidName:fidList.append(fid)
arcpy.AddMessage(fidList)
fidCount = len(fidList)for row in arcpy.da.SearchCursor(infc, fidList):pntArray = filter(None, row[1].getPart()[0])pntCount = len(list(pntArray))f.write(str(pntCount)+",")for i in range(2, fidCount):if row[i] != None:f.write(str(row[i])+",")elif row[i] == None:f.write(",")f.write("@"+"\n")ringNum = 1for part in row[1]:pnt_num = 1for point in part:if point:f.write("J{},{},{},{}".format(pnt_num, ringNum, format(point.Y, '.3f'), format(point.X, '.3f'))+"\n")else:pnt_num -= 1ringNum += 1pnt_num += 1

工具参数

 参数验证

class ToolValidator:# Class to add custom behavior and properties to the tool and tool parameters.def __init__(self):# set self.params for use in other functionself.params = arcpy.GetParameterInfo()def initializeParameters(self):# Customize parameter properties. # This gets called when the tool is opened.returndef updateParameters(self):# Modify parameter values and properties.# This gets called each time a parameter is modified, before # standard validation.txtPath = self.params[1].valueAsTextsuffix = ".txt"if txtPath.endswith(suffix)==False:self.params[1].value=txtPath+".txt"returndef updateMessages(self):# Customize messages for the parameters.# This gets called after standard validation.return# def isLicensed(self):#     # set tool isLicensed.# return True# def postExecute(self):#     # This method takes place after outputs are processed and#     # added to the display.# return

工具说明

  1. 要素类需要拆分多部件后再使用工具转txt
  2. 图形的点数默认包含在输出txt文件的要素属性行中的第一个
  3. 工具界面输出字段的顺序与输出txt文件中要素属性行的属性顺序一致

工具下载

        代码可自取,完整工具请私信联系。传播请注明出处。

相关内容

热门资讯

【PdgCntEditor】解... 一、问题背景 大部分的图书对应的PDF,目录中的页码并非PDF中直接索引的页码...
修复 爱普生 EPSON L4... L4151 L4153 L4156 L4158 L4163 L4165 L4166 L4168 L4...
在Word、WPS中插入AxM... 引言 我最近需要写一些文章,在排版时发现AxMath插入的公式竟然会导致行间距异常&#...
监控摄像头接入GB28181平... 流程简介将监控摄像头的视频在网站和APP中直播,要解决的几个问题是:1&...
protocol buffer... 目录 目录 什么是protocol buffer 1.protobuf 1.1安装  1.2使用...
Windows10添加群晖磁盘... 在使用群晖NAS时,我们需要通过本地映射的方式把NAS映射成本地的一块磁盘使用。 通过...
【前端】‘??‘与‘||‘有什... 0 问题 经常写const data = res.data.a ?? ''或者const d...
牛客计算器的改良(Python... 文章目录1.题目描述2.输入描述:3.输出描述:4.示例15.分析6.代码7.结语 链接࿱...
【Redis】Redis持久化... 目录 1.Redis持久化 1.1.RDB持久化 1.1.1.执行时机 1.1.2.RDB原理 1....
ChatGPT 怎么用最新详细... ChatGPT 以其强大的信息整合和对话能力惊艳了全球,在自然语言处理上面表现出了惊人...