CLI 目录 横向对比 FCRS-1.0 标准 /llms.txt
← 返回 CLI 目录

GDAL ogr2ogr

$ ogr2ogr 基金会 中风险
OSGeo · 数据库与数据处理 · MIT · macos / linux / windows

ogr2ogr(搭配 ogrinfo)是 OSGeo 出品的业界标准地理空间矢量 ETL 工具。支持在 80+ 种矢量格式(包括 GeoJSON、GeoParquet -f Parquet、Shapefile、GeoPackage 与 PostGIS)间执行格式转换、坐标系重投影与 OGR SQL 过滤。

FCRS-1.0 综合评分
81 /100
良好 (Good)
中置信度 (源码/文档)
零摩擦安装命令
brew install gdal
CLI vs MCP 选型建议 仅 CLI 可用

在本地依托 GDAL/PROJ 完成精确坐标系重投影(-t_srs)与 GeoParquet/GeoJSON/Shapefile 转换,无需编写 geopandas 脚本。

Agent 友好度体检单

— 原生 JSON 输出
✓ 字段裁剪
✓ 无头非交互
— 支持 Dry-Run
— 只读模式开关
— 支持 NO_COLOR
✓ 自省/Schema 发现
— 官方 SKILL.md

当前为静态评估(本机尚未安装或尚未运行探针)。可在本地运行 npm run data:probe 并提交 data/probes/ 升级为实测证据。

FCRS-1.0 六维评分拆解

Agent 友好度 19 / 25

非交互执行且支持 /vsistdout/ 与 ogrinfo -json,但“目标在前、源在后”的参数顺序与各类驱动参数需要格外留心。

  • Supports -sql, /vsistdout/, and companion ogrinfo -json
  • Non-standard dst src argument order
安全与权限边界 21 / 25

需显式指定目标文件或 PostGIS 连接;使用 -overwrite 与 -update 时可能覆盖已有图层。

  • Destination-first syntax; -overwrite poses table replacement risk
安装与运行摩擦 10 / 15

依赖庞大的 C++ 工具链(gdal、proj、geos、arrow),可通过 Homebrew/conda/apt 安装,部分驱动(如 Parquet)取决于编译选项。

  • Large native dependency tree; driver support varies by build
能力覆盖与边际价值 15 / 15

无与伦比的 80+ 矢量格式兼容性、空间裁剪(-clipsrc)与坐标重投影(-t_srs)能力。

  • Canonical geospatial ETL across GeoJSON, GeoParquet, Shapefile, PostGIS
维护与来源背书 9 / 10

OSGeo 基金会旗舰项目(OSGeo/gdal),采用 MIT 协议。

  • Official OSGeo OSGeo/gdal repository
文档与可验证性 7 / 10

gdal.org 官方手册详尽,但各驱动专属的 -lco/-dsco 选项分散在大量子页面中。

  • Comprehensive docs at gdal.org/en/stable/programs/ogr2ogr.html

安全边界、鉴权与放权指南

鉴权方式
无需鉴权 环境变量密钥 本地配置文件
凭证存储位置

本地文件无需凭据;PostGIS 或云端 /vsis3/ 驱动读取标准 libpq(PGPASSWORD、~/.pgpass)或 AWS 环境变量。

潜在副作用
只读查询 本地写入 远端写入
费用与配额提示

MIT 开源 OSGeo 工具集,完全免费。

可复制到 CLAUDE.md / AGENTS.md 的安全护栏
# GDAL ogr2ogr Agent Rules
- Note argument order: `ogr2ogr [opts] <dst_dataset> <src_dataset>` (destination comes FIRST!).
- Inspect metadata first with `ogrinfo -json -so <file>` before converting.
- Avoid `-overwrite` on existing PostGIS tables or GeoPackages without explicit user approval.

Agent 高频安全命令配方

只读查询(安全推荐)

以 JSON 查看矢量图层与 Schema
ogrinfo -json -so input.parquet

使用配套命令 ogrinfo -json -so(仅摘要)检查坐标系、几何类型与属性 Schema。

过滤 GeoParquet 并向标准输出流式输出 GeoJSON
ogr2ogr -f GeoJSON /vsistdout/ input.parquet -sql "SELECT name, geom FROM input LIMIT 20"

通过 -sql 筛选属性并直接写入 /vsistdout/,不生成本地文件。

受控写入与预演

将 GeoJSON 重投影并转为 GeoParquet
ogr2ogr -f Parquet -t_srs EPSG:4326 out.parquet in.geojson

将矢量要素重投影至 WGS84 并输出为 Apache GeoParquet 文件(out.parquet)。

核心优势

  • + 全面支持 GeoJSON、GeoParquet、Shapefile、FlatGeobuf 与 PostGIS 等 80+ 种空间格式。
  • + 配套 ogrinfo -json -so 为 Agent 提供干净的 JSON Schema 与坐标系摘要。
  • + 基于 PROJ 实现高精度坐标变换(-s_srs / -t_srs)。

注意事项与踩坑点

  • ! 参数顺序为目标在前、源在后(ogr2ogr dst src)——写反可能误覆写源文件!
  • ! 输出 GeoParquet(-f Parquet)要求 GDAL 编译时启用了 Apache Arrow/Parquet 支持(可用 ogr2ogr --formats 检查)。

已验证兼容的 Agent 宿主

Claude Code Codex CLI Gemini CLI