示例展示
代码
只读取excel中含有XY字段的文件,并将矢量命名为excel文件名称。
import os
import pandas as pd
import arcpy
folder_path =r"C:\Users\admin\Desktop\excelfile"
extension="xlsx"
files = [file for file in os.listdir(folder_path) if file.endswith('.' + extension)]
#坐标系
spatial=arcpy.SpatialReference(4326)
for filename in files:#无后缀的文件名filename_without_extension = os.path.splitext(filename)[0]#文件路径filepath = os.path.join(folder_path, filename)print(filepath)#读取exceldata = pd.read_excel(filepath)#创建要素类if 'X' in data.columns:pointshp=arcpy.CreateFeatureclass_management(folder_path,filename_without_extension,"POINT","","","",spatial)with arcpy.da.InsertCursor(pointshp, ["SHAPE@XY"]) as cursor:for index, row in data.iterrows():cursor.insertRow([(row['X'], row['Y'])])