用Arcpy编写点线面要素转ASCII文本(txt)

最近在学Arcpy顺带做了点线面要素转线要素的实验
arcpy一定要先下arcpy,然后在环境里面选择arcpy的py框架
以下为实验数据:
在这里插入图片描述
注意:运行程序时一定要关闭arcmap一定要!

(1)我先做的是点、线、面要素的特征点转换为文本文件
以下为脚本截图
以下为点矢量转txt文本

#coding:utf-8
import  arcpy

txtPath = r"C:\Users\lenovo\Desktop\arcpy\test\points.txt"#不能识别汉字
shpPath = r"C:\Users\lenovo\Desktop\arcpy\test\点.shp"

with open(txtPath, "w") as filename:
    cur = arcpy.SearchCursor(shpPath)
    filename.write("Points" + "\n")
    pointindex = 0
    index = 0
    for r in cur:
        index=index+1
        geom = r.shape
        point = geom.getPart()
        #for point in points:
        info = str(pointindex) + " " + str(point.X) + " " + str(point.Y) + "\n"
        filename.write((info))
        pointindex = pointindex + 1
    print index
    print "finished"

此为线矢量转txt文本

#coding:utf-8
import  arcpy

txtPath = r"C:\Users\lenovo\Desktop\arcpy\test\polylines.txt"
shpPath = r"C:\Users\lenovo\Desktop\arcpy\test\线.shp"

with open(txtPath, "w") as filename:
   cur = arcpy.SearchCursor(shpPath)
   lineindex = 0
   filename.write("Polyline" + "\n")
   for r in cur:
       line = r.getValue("SHAPE")
       array = line.getPart(0)  # 得到每条线上每个点的数据
       pointindex = 0
       filename.write(str(pointindex) + " " + str(lineindex) + "\n")
       lineindex = lineindex + 1
       for i in range(0, array.count):
           print array.count
           info = str(pointindex) + " " + str(array[i].X) + " " + str(array[i].Y) + "\n"
           filename.write((info))
           pointindex = pointindex + 1
   print "finished"

此为面矢量转txt文本

#coding:utf-8
import  arcpy

txtPath = r"C:\Users\lenovo\Desktop\arcpy\test\polygan.txt"#不能识别汉字
shpPath = r"C:\Users\lenovo\Desktop\arcpy\test\面.shp"

with open(txtPath, "w") as filename:
    cur = arcpy.SearchCursor(shpPath)
    areaindex = 0
    filename.write("Polygan" + "\n")
    for r in cur:
        line = r.getValue("SHAPE")
        array = line.getPart(0)  # 得到每条上每个点的数据
        pointindex = 0
        filename.write(str(pointindex) + " " + str(areaindex) + "\n")
        areaindex = areaindex + 1
        for i in range(1, array.count):
            info = str(pointindex) + " " + str(array[i].X) + " " + str(array[i].Y) + "\n"
            filename.write((info))
            pointindex = pointindex + 1
    print "finished"

运行后的效果截图:
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值