簡體   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