之前介绍过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
代码可自取,完整工具请私信联系。传播请注明出处。
下一篇:(一)K8S 资源管理方式