从.txt文件中的数据创建多个要素类

时间:2017-03-10 00:45:14

标签: python gis arcgis

我正在尝试使用扩展名为.txt的数据创建多个要素类。我的代码运行,但只生成一个.shp文件。选中时变量xyTable确实包含所有文件扩展名。然后,它们应单独运行两个Arcpy函数,并生成根据其.txt文件命名的相关要素类文件。

{{1}}

1 个答案:

答案 0 :(得分:0)

看起来您没有为FeatureClassToFeatureClass工具提供唯一的shapefile名称。在第一个For循环结束后,fileSHP不会改变。看起来你已经设置了shpFileArray来保存fileSHP列表。也许尝试这样的东西来保存你的第一个For循环中的fileSHP集,并在第二个For循环中引用它们。我的python可能不完全正确,但我认为这个想法是。

import arcpy
import os
import tempfile
import shutil
shpFileArray = []
print "\n"
arcpy.env.overwriteOutput = True

newFolder = "destinationpath"
if os.path.exists(newFolder):
    tmp = tempfile.mktemp(dir=os.path.dirname(newFolder))
    shutil.move(newFolder, tmp)
    shutil.rmtree(tmp)
os.makedirs(newFolder)

arcpy.env.workspace = newFolder

for file in os.listdir("sourcepath"):
    layerName = file[:-4]
    fileSHP = layerName+".shp"
    shpFileArray.append(fileSHP)



for idx, file in enumerate(os.listdir("sourcepath")):
       if file.endswith(".txt"):
            xyTable = (os.path.join("destinationpath", file))
            outShape = shapeFileArray[idx]


            arcpy.MakeXYEventLayer_management(table= xyTable, in_x_field="EastingM", in_y_field="NorthingM", out_layer="layerName",...continues...


            arcpy.FeatureClassToFeatureClass_conversion(in_features="layerName", out_path="destinationpath", out_name= outShape,....continues....
相关问题