【问题标题】:Creating Multiple featureclasses from data in .txt Files从 .txt 文件中的数据创建多个要素类
【发布时间】:2017-03-10 00:45:14
【问题描述】:

我正在尝试从扩展名为 .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....

【问题讨论】:

    标签: python gis arcgis


    【解决方案1】:

    看起来您没有为 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....
    

    【讨论】:

      猜你喜欢
      • 2014-09-17
      • 2016-01-06
      • 2021-09-21
      • 2019-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-17
      • 2019-06-19
      相关资源
      最近更新 更多