行业知识
【ArcPy】批量读取文件夹excel中XY并转为点shp
2026-10-31 20:28:57
来源:互联网转载
示例展示
代码
只读取excel��含有XY字段的文件,并将矢量命名为excel文件名称。
import osimport pandas as pdimport arcpyfolder_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) #读取excel data = 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'])])
上一篇:怎么建新闻网站?
下一篇:视频发布服务器怎么装?