求批量将ESRI E00文件转换为Shapefile的R/Python代码或方法
批量转换ESRI E00文件至Shapefile的方案
Python 实现方案
使用GDAL库的ogr模块可实现批量转换,无需依赖ArcGIS工具。先通过pip install gdal安装对应系统版本的GDAL库。
代码示例:
import os from osgeo import ogr # 配置输入输出路径 input_dir = r"C:\your_e00_files_folder" output_dir = r"C:\output_shapefiles_folder" # 创建输出目录(不存在则新建) if not os.path.exists(output_dir): os.makedirs(output_dir) # 遍历所有E00文件 for filename in os.listdir(input_dir): if filename.lower().endswith(".e00"): input_path = os.path.join(input_dir, filename) output_name = os.path.splitext(filename)[0] + ".shp" output_path = os.path.join(output_dir, output_name) # 读取E00数据源 e00_ds = ogr.Open(input_path) if not e00_ds: print(f"无法读取文件: {input_path}") continue # 获取图层(E00通常仅有一个图层) layer = e00_ds.GetLayer() if not layer: print(f"文件无有效图层: {input_path}") continue # 创建Shapefile数据源 driver = ogr.GetDriverByName("ESRI Shapefile") if os.path.exists(output_path): driver.DeleteDataSource(output_path) output_ds = driver.CreateDataSource(output_path) if not output_ds: print(f"无法创建输出文件: {output_path}") continue # 复制图层至Shapefile output_ds.CopyLayer(layer, layer.GetName()) # 释放资源 e00_ds = None output_ds = None print(f"转换完成: {filename} -> {output_name}")
R 实现方案
使用sf包(GDAL的R绑定)处理批量转换,先安装依赖:install.packages(c("sf", "fs"))。
代码示例:
library(sf) library(fs) # 配置路径 input_dir <- "C:/your_e00_files_folder" output_dir <- "C:/output_shapefiles_folder" # 创建输出目录 dir_create(output_dir, recurse = TRUE) # 获取所有E00文件路径 e00_files <- dir_ls(input_dir, regexp = "\\.e00$", ignore.case = TRUE) # 批量转换 for (file in e00_files) { e00_sf <- st_read(file, quiet = TRUE) if (is.null(e00_sf)) { message(paste("转换失败:", file)) next } output_name <- path_ext_set(path_file(file), "shp") output_path <- path(output_dir, output_name) st_write(e00_sf, output_path, driver = "ESRI Shapefile", quiet = TRUE) message(paste("转换完成:", file, "->", output_path)) }
其他可行方法
GDAL命令行批量处理
无需编写代码,用GDAL的ogr2ogr命令行配合脚本实现:
Windows批处理脚本(.bat):
@echo off set INPUT_DIR=C:\your_e00_files_folder set OUTPUT_DIR=C:\output_shapefiles_folder if not exist %OUTPUT_DIR% mkdir %OUTPUT_DIR% for %%f in (%INPUT_DIR%\*.e00) do ( ogr2ogr -f "ESRI Shapefile" "%OUTPUT_DIR%\%%~nf.shp" "%%f" echo 已转换: %%~nf.e00 -> %%~nf.shp ) pause
Linux/macOS Shell脚本:
INPUT_DIR="/path/to/your/e00/files" OUTPUT_DIR="/path/to/output/folder" mkdir -p $OUTPUT_DIR for file in $INPUT_DIR/*.e00; do filename=$(basename "$file" .e00) ogr2ogr -f "ESRI Shapefile" "$OUTPUT_DIR/$filename.shp" "$file" echo "已转换: $file -> $OUTPUT_DIR/$filename.shp" done
注意事项
- 确保E00文件为有效格式,损坏或加密文件需单独处理。
- 转换后的Shapefile会保留原文件所有属性,可在GIS工具中验证完整性。
内容的提问来源于stack exchange,提问作者Emmelie Paquette
相关产品推荐
相关产品推荐

