转载:https://blog.csdn.net/qq_42257561/article/details/111707516
目标:将点shp批量转换成线shp。
import os
import arcpy
root = "存放点shp的路径" #需要转的点shp文件目录(注意/)
def findtxt(path, ret):
"""Finding the *.shp file in specify path"""
filelist = os.listdir(path)
for filename in filelist:
de_path = os.path.join(path, filename)
if os.path.isfile(de_path):
if de_path.endswith(".shp"): # Specify to find the shp file.
ret.append(de_path)
else:
findtxt(de_path, ret)
ret = []
findtxt(root, ret)
i = 0
for path in ret:
i = i+1
outpath = "保存生成线shp的路径/" + str(i) #输出路径
print(outpath)
print(path)
arcpy.PointsToLine_management(path, outpath)
输出结果: