Python顺序请求:ArcMap中的数据处理自动化

2024-04-19 16:28:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我的python技能非常有限(几乎没有),而且我从来没有为ArcMap创建过自动、连续的请求。以下是我想编写的步骤,如有任何建议,将不胜感激

  1. 找到文件夹
  2. 导入“第一个”文件(表csv)(有500多个CV,命名约定不是顺序的)
  3. 将csv连接到HUC08形状文件
  4. 在字段名“name”下选择不带空值的数据
  5. 将选定数据保存为my FoTX.gdb中的图层文件
  6. 移动到文件夹中的下一个文件并完成相同的操作,直到所有操作都完成

Tags: 文件csv数据name文件夹顺序技能步骤
1条回答
网友
1楼 · 发布于 2024-04-19 16:28:52
#Part of the code. The rest depends mostly on your data
#Set environment settings
arcpy.env.workspace = 'C:/data' #whatever it is for you. you can do this or not


import os, arcpy, csv

   mxd = arcpy.mapping.MapDocument("CURRENT")
   folderPath=os.path.dirname(mxd.filePath)

   #Loop through each csv file
    count = 0

    for f_name in os.listdir(folderPath):
      fullpath = os.path.join(folderPath, f_name)
      if os.path.isfile(fullpath):
       if f_name.lower().endswith(".csv"):
             #import csv file and join to shape file code here

             # Set local variables
             in_features = ['SomeNAME.shp', 'SomeOtherNAME.shp'] # if there are more 
                                                                 #then one
             out_location = 'C:/output/FoTX.gdb'
             # out_location =os.path.basename(gdb.filePath) #or if the gdb is in the 
                                                            #same folder as the csv 
                                                            #files

             # Execute FeatureClassToGeodatabase
             arcpy.FeatureClassToGeodatabase_conversion(in_features, out_location)

    if count ==0:
      print "No CSV files in this folder"

相关问题 更多 >