繁体   English   中英

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

[英]Creating Multiple featureclasses from data in .txt Files

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

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"



for file in os.listdir("sourcepath"):
       if file.endswith(".txt"):
            xyTable = (os.path.join("destinationpath", file))


            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= fileSHP,....continues....

看起来您没有给FeatureClassToFeatureClass工具提供唯一的shapefile名称。 第一个For循环完成后,fileSHP不会更改。 看起来您已经设置了shpFileArray来保存fileSHP的列表。 也许尝试这样的操作将您的fileSHP集保存在第一个For循环中,并在第二个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....

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM