最近在学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"
运行后的效果截图: