arcgis10.2.2工具箱Python2.7脚本:用来数据批量导出Shapefile、File Geodatabase 或 CSV或xls
时间: 2023-12-14 21:38:25 浏览: 138
以下是一个用 Python 2.7 编写的 ArcGIS 10.2.2 工具箱脚本,可以用来批量导出 Shapefile、File Geodatabase 或 CSV 或 xls 数据:
```python
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# Batch Export Tool
# Description: Batch export data from a workspace to either shapefiles, file geodatabases, CSV or xls files
# Author: Your Name
# Created: Date
# Last Modified: Date
# ---------------------------------------------------------------------------
# Import arcpy module
import arcpy
import os
# Script arguments
Input_Workspace = arcpy.GetParameterAsText(0) # Input workspace
Output_Folder = arcpy.GetParameterAsText(1) # Output folder
Output_Format = arcpy.GetParameterAsText(2) # Output format, shapefile, file geodatabase, CSV or xls
# Environment settings
arcpy.env.workspace = Input_Workspace
arcpy.env.overwriteOutput = True
# List all feature classes in the workspace
fc_list = arcpy.ListFeatureClasses()
# Loop through each feature class and export it to the chosen format
for fc in fc_list:
# Create the output path for each feature class
out_path = os.path.join(Output_Folder, os.path.splitext(fc)[0])
# Export to shapefile format
if Output_Format == "Shapefile":
arcpy.FeatureClassToShapefile_conversion(fc, out_path)
# Export to file geodatabase format
elif Output_Format == "File Geodatabase":
arcpy.FeatureClassToGeodatabase_conversion(fc, Output_Folder)
# Export to CSV format
elif Output_Format == "CSV":
arcpy.TableToTable_conversion(fc, Output_Folder, os.path.splitext(fc)[0] + ".csv")
# Export to xls format
elif Output_Format == "xls":
arcpy.TableToExcel_conversion(fc, os.path.join(Output_Folder, os.path.splitext(fc)[0] + ".xls"))
# Print completion message
arcpy.AddMessage("Batch export completed successfully!")
```
在使用此工具箱脚本之前,请确保已经在 ArcGIS 中创建好了工具箱,并将此脚本作为一个工具添加到工具箱中。然后,您可以运行此工具,选择输入工作区、输出文件夹和输出格式,然后单击“运行”按钮即可开始批量导出数据。
阅读全文