简体   繁体   English

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

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

I am trying to create multiple feature classes from data with .txt extension. 我正在尝试从扩展名为.txt的数据创建多个要素类。 My code runs, but only produces one .shp file. 我的代码运行,但是只生成一个.shp文件。 The variable xyTable when checked does contain all the file extensions. 选中时,变量xyTable确实包含所有文件扩展名。 These then should individually run through both Arcpy functions and produce the relevant featureclass files named in accordance with their .txt files. 然后,它们应分别通过这两个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....

Looks like you are not giving the FeatureClassToFeatureClass tool unique shapefile names. 看起来您没有给FeatureClassToFeatureClass工具提供唯一的shapefile名称。 After the first For loop finishes, fileSHP doesn't change. 第一个For循环完成后,fileSHP不会更改。 Looks like you have the shpFileArray set up to hold the list of fileSHPs. 看起来您已经设置了shpFileArray来保存fileSHP的列表。 Perhaps try something like this to save your set of fileSHPs in the first For loop and refer to them in the second For loop. 也许尝试这样的操作将您的fileSHP集保存在第一个For循环中,并在第二个For循环中引用它们。 My python might not be exactly right, but I think the idea is. 我的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