Gdal Api logo

Gdal Api

Community
znlgis
gdal-api

Use when programming against GDAL/OGR in C, C++, Python, Java, or .NET — raster/vector I/O, gdal.UseExceptions, OGRSpatialReference transforms, gdal.Translate / gdal.Warp, VRT/COG, or fixing "no driver registered" and UnsatisfiedLinkError; C++ gdal-config, Maven org.gdal:gdal 3.13.0, NuGet MaxRev.Gdal.Core.

Overview

Publisherznlgis
Repositoryopengis-skills
Skill namegdal-api
Stars
76
Forks
12
Bundled files
2
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 2 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by znlgis on GitHub. Read the source before you install it.

Installation

Install the Gdal Api AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/znlgis/opengis-skills/tree/main/gis/gdal-api
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/znlgis/opengis-skills.git /tmp/opengis-skills
mkdir -p .claude/skills
cp -r /tmp/opengis-skills/gis/gdal-api .claude/skills/gdal-api
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Gdal Api in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Gdal Api on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Gdal Api is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

项目地址: https://github.com/OSGeo/gdal

API 总览文档: https://gdal.org/en/stable/api/index.html

C/C++ API 参考: https://gdal.org/en/stable/api/index.html#c-api

Python API 参考: https://gdal.org/en/stable/api/python/index.html

Java API 参考: https://gdal.org/en/stable/api/java/index.html

C# API 参考: https://gdal.org/en/stable/api/csharp/index.html

最新版本: 3.13.3(截至 2026-10,下载页);Java 绑定(Maven Central)3.13.0

许可证: MIT

概述

GDAL 是地理空间数据处理的事实标准库,由 OSGeo 基金会维护。它提供:

  • 200+ 栅格驱动:GeoTIFF、NetCDF、HDF5、COG、JPEG2000 等
  • 100+ 矢量驱动:Shapefile、GeoJSON、GeoPackage、PostGIS、FlatGeobuf 等
  • 坐标参考系统:基于 PROJ 的坐标变换与投影转换
  • 栅格分析:重采样、镶嵌、裁剪、波段运算、DEM 分析等
  • 矢量操作:空间过滤、属性查询、要素创建与编辑等

GDAL 核心以 C++ 实现,同时通过 SWIG 提供 Python、Java、C# 三种语言绑定,各语言 API 与 C++ 保持一致的类与方法命名。


环境准备

C++ 环境

bash
# Linux (Debian/Ubuntu)
apt-get install libgdal-dev

# macOS (Homebrew)
brew install gdal

# CMake 项目中链接 GDAL
# CMakeLists.txt
find_package(GDAL REQUIRED)
target_link_libraries(myapp PRIVATE GDAL::GDAL)

Python 环境

bash
# pip 安装(需系统已安装 GDAL 库)
pip install GDAL

# Conda 安装(推荐,自动处理 C 库依赖)
conda install -c conda-forge gdal

# 验证
python -c "from osgeo import gdal; print(gdal.VersionInfo())"

Java 环境

xml
<!-- Maven 依赖(Java 绑定版本随 GDAL 次版本发布,Maven Central 当前最新 3.13.0) -->
<dependency>
    <groupId>org.gdal</groupId>
    <artifactId>gdal</artifactId>
    <version>3.13.0</version><!-- 最新版查看 https://central.sonatype.com/artifact/org.gdal/gdal -->
</dependency>
groovy
// Gradle
implementation 'org.gdal:gdal:3.13.0'

注意: Java 绑定需要在系统 PATH(Windows)或 LD_LIBRARY_PATH(Linux)中找到 gdalalljni 本地库。

C# 环境

bash
# .NET Core / .NET 5+ 项目
dotnet add package MaxRev.Gdal.Core
dotnet add package MaxRev.Gdal.LinuxRuntime.Minimal   # Linux
dotnet add package MaxRev.Gdal.WindowsRuntime.Minimal  # Windows

注意: 官方 SWIG 绑定命名空间为 OSGeo.GDAL、OSGeo.OGR、OSGeo.OSR。NuGet 包 MaxRev.Gdal.Core 是社区维护的跨平台封装,2026-10 的最新版为 3.13.3.583(对应 GDAL 3.13.3),运行时包需与 MaxRev.Gdal.Core 主版本一致。


核心 API 一览

GDAL API 在四种语言中保持一致的类结构,下表列出核心类及其作用:

栅格 API 核心类

类C++ 头文件 / 模块用途
GDALDrivergdal_priv.h / osgeo.gdal栅格驱动——注册格式、创建数据集
GDALDatasetgdal_priv.h / osgeo.gdal(推荐)栅格数据集——打开、读写、获取元数据
GDALRasterBandgdal_priv.h / osgeo.gdal栅格波段——读写像素、获取统计信息
GDALColorTablegdal_priv.h / osgeo.gdal颜色表——索引颜色映射
GDALRasterAttributeTablegdal_priv.h / osgeo.gdal栅格属性表

矢量 API 核心类(OGR)

类C++ 头文件 / 模块用途
OGRSFDriver / GDALDriverogrsf_frmts.h / osgeo.ogr矢量驱动
GDALDataset / OGRDataSourceogrsf_frmts.h / osgeo.ogr(推荐)矢量数据源——管理图层集合
OGRLayerogrsf_frmts.h / osgeo.ogr(推荐)矢量图层——读写要素、空间过滤
OGRFeatureogr_feature.h / osgeo.ogr矢量要素——属性 + 几何
OGRFeatureDefnogr_feature.h / osgeo.ogr要素定义——字段结构
OGRFieldDefnogr_feature.h / osgeo.ogr字段定义——名称、类型
OGRGeometryogr_geometry.h / osgeo.ogr几何基类(Point、LineString、Polygon 等)

空间参考类(OSR)

类C++ 头文件 / 模块用途
OGRSpatialReferenceogr_spatialref.h / osgeo.osr(推荐)空间参考系统——定义 CRS
OGRCoordinateTransformationogr_spatialref.h / osgeo.osr(推荐)坐标变换——在不同 CRS 间转换坐标

各语言模块 / 命名空间对照

功能域C++PythonJavaC#
栅格#include "gdal_priv.h"from osgeo import gdalimport org.gdal.gdal.*using OSGeo.GDAL;
矢量#include "ogrsf_frmts.h"from osgeo import ogrimport org.gdal.ogr.*using OSGeo.OGR;
空间参考#include "ogr_spatialref.h"from osgeo import osrimport org.gdal.osr.*using OSGeo.OSR;

栅格数据读取与创建写入的完整 API 与代码示例见 reference/raster-api.md 矢量数据读取与创建写入的完整 API 与代码示例见 reference/vector-api.md

坐标参考系统与坐标变换

C++

cpp
#include "ogr_spatialref.h"

// 定义坐标系
OGRSpatialReference srcSRS, dstSRS;
srcSRS.SetWellKnownGeogCS("WGS84");        // EPSG:4326
dstSRS.importFromEPSG(3857);               // Web Mercator

// 创建坐标变换
OGRCoordinateTransformation *transform =
    OGRCreateCoordinateTransformation(&srcSRS, &dstSRS);

// 变换坐标
double x = 116.4, y = 39.9;
if (transform->Transform(1, &x, &y)) {
    // x, y 已变换为 EPSG:3857 坐标
}

// C++ 用 DestroyCT 归还;OCTDestroyCoordinateTransformation 是 C API(接收 OGRCoordinateTransformationH)
OGRCoordinateTransformation::DestroyCT(transform);

Python

python
from osgeo import osr

# 定义坐标系
src_srs = osr.SpatialReference()
src_srs.SetWellKnownGeogCS("WGS84")        # EPSG:4326

dst_srs = osr.SpatialReference()
dst_srs.ImportFromEPSG(3857)               # Web Mercator

# 创建坐标变换
transform = osr.CoordinateTransformation(src_srs, dst_srs)

# 变换坐标
x, y, z = transform.TransformPoint(116.4, 39.9)

Java

java
import org.gdal.osr.SpatialReference;
import org.gdal.osr.CoordinateTransformation;
import org.gdal.osr.osr;

// 定义坐标系
SpatialReference srcSRS = new SpatialReference();
srcSRS.SetWellKnownGeogCS("WGS84");        // EPSG:4326

SpatialReference dstSRS = new SpatialReference();
dstSRS.ImportFromEPSG(3857);               // Web Mercator

// 创建坐标变换
CoordinateTransformation transform =
    osr.CreateCoordinateTransformation(srcSRS, dstSRS);

// 变换坐标
double[] point = new double[]{116.4, 39.9, 0};
transform.TransformPoint(point);
// point[0], point[1] 已变换为 EPSG:3857 坐标

C#

csharp
using OSGeo.OSR;

// 定义坐标系
SpatialReference srcSRS = new SpatialReference("");
srcSRS.SetWellKnownGeogCS("WGS84");        // EPSG:4326

SpatialReference dstSRS = new SpatialReference("");
dstSRS.ImportFromEPSG(3857);               // Web Mercator

// 创建坐标变换
CoordinateTransformation transform =
    new CoordinateTransformation(srcSRS, dstSRS);

// 变换坐标
double[] point = new double[3] { 116.4, 39.9, 0 };
transform.TransformPoint(point);
// point[0], point[1] 已变换为 EPSG:3857 坐标

栅格格式转换与重投影的完整示例见 reference/raster-api.md 矢量格式转换、空间过滤、几何操作与 GeoPackage 读写的完整示例见 reference/vector-api.md 常用栅格数据格式与创建选项详见 reference/raster-api.md 常用矢量数据格式详见 reference/vector-api.md

典型工作流:矢量筛选与坐标变换

端到端示例(Python):读取 Shapefile → 空间 + 属性过滤 → 写出 GeoJSON:

python
from osgeo import gdal, ogr, osr

gdal.UseExceptions()                      # 启用异常模式,便于排错

src_ds = ogr.Open("cities.shp")
layer = src_ds.GetLayer(0)
layer.SetSpatialFilterRect(116.0, 39.5, 117.0, 40.5)   # 空间粗筛(走空间索引)
layer.SetAttributeFilter("POPULATION > 1000000")        # 属性过滤

dst_srs = osr.SpatialReference()
dst_srs.ImportFromEPSG(4326)

gdal.VectorTranslate(
    "cities_filtered.geojson", src_ds,
    format="GeoJSON", dstSRS=dst_srs,
    layers=[layer.GetName()]
)

src_ds = None                             # 释放数据源

栅格端到端(读取 → 重投影 → 压缩写出)等价流程见 reference/raster-api.md。

典型应用场景

场景C++PythonJavaC#
读取栅格元数据GDALOpen + GetGeoTransformgdal.Open + GetGeoTransformgdal.Open + GetGeoTransformGdal.Open + GetGeoTransform
栅格格式转换CreateCopygdal.Translategdal.TranslateGdal.wrapper_GDALTranslate
栅格重投影GDALAutoCreateWarpedVRTgdal.Warpgdal.WarpGdal.Warp
读取矢量要素GDALOpenEx + GetNextFeatureogr.Open + 迭代ogr.Open + GetNextFeatureOgr.Open + GetNextFeature
矢量格式转换CopyLayer / CreateFeaturegdal.VectorTranslateogr.CopyLayerOgr.CopyLayer
坐标变换OGRCreateCoordinateTransformationosr.CoordinateTransformationosr.CreateCoordinateTransformationnew CoordinateTransformation
创建缓冲区OGRGeometry::Buffergeom.Buffergeom.Buffergeom.Buffer
空间查询SetSpatialFilterRectSetSpatialFilterRectSetSpatialFilterRectSetSpatialFilterRect
SQL 查询ExecuteSQLExecuteSQLExecuteSQLExecuteSQL
波段运算RasterIO 手动计算gdal_calc.py / NumPyRasterIO 手动计算RasterIO 手动计算

常见问题

类别问题解决
通用功能调用报「驱动未注册」先注册:C++/Python GDALAllRegister();Java gdal.AllRegister();C# Gdal.AllRegister();矢量另需 OGRRegisterAll() / ogr.RegisterAll()
通用文件损坏 / 写入未生效及时释放资源:C++ GDALClose()、OGRFeature::DestroyFeature();Python 赋值 None;Java .delete();C# .Dispose()
通用经纬度顺序颠倒GDAL 3.0+ 默认纬度在前;用 OGRSpatialReference::SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER) 强制经度在前
通用多线程下崩溃GDAL 全局状态非线程安全:每个线程使用独立 GDALDataset,避免并发写同一数据集
通用大栅格内存溢出用 RasterIO 指定窗口分块读写,避免一次性读入整个影像
通用报错信息不明确C++ 用 CPLGetLastErrorMsg(),Python 用 gdal.GetLastErrorMsg() 获取详细错误
C++WKT 等 C 字符串泄漏用 CPLFree() 释放(如 exportToWkt 返回值);几何用 OGRGeometryFactory::destroyGeometry()
C++坐标变换释放方式混用C++ 用 OGRCoordinateTransformation::DestroyCT();OCTDestroyCoordinateTransformation() 只接收 C API 的 OGRCoordinateTransformationH
C++编译 / 链接失败用 gdal-config --cflags --libs 或 CMake find_package(GDAL) 配置编译参数
Python出错却不抛异常脚本开头调用 gdal.UseExceptions() 启用异常模式
Python如何高效读写像素band.ReadAsArray() / band.WriteArray(array) 直接与 NumPy 数组互转
JavaUnsatisfiedLinkError确保 gdalalljni(Linux libgdalalljni.so、Windows gdalalljni.dll)在 java.library.path 中
Java选项参数如何传递许多方法使用 java.util.Vector<String> 传递选项参数
C#本地库加载失败按目标平台引入对应 NuGet 运行时包(Linux / Windows / macOS)
C#中文路径乱码字符串参数默认 UTF-8,注意编码一致性

AI 使用建议

  • 本技能的组织:主文件给高频用法,完整参数表与高级示例在 reference/raster-api.md、reference/vector-api.md,需要时再展开;示例工程与生成的数据写到工作目录,不要改动技能目录本身。
  • 执行环境:编译与运行在终端 / shell 中执行(Windows 用 PowerShell)。C++ 用 gdal-config --cflags --libs 或 CMake find_package(GDAL REQUIRED);Python 用装好绑定的解释器;Java 的 gdalalljni、.NET 的 MaxRev 运行时包必须与平台、架构匹配。
  • 先探测版本:ogrinfo --version、python -c "from osgeo import gdal; print(gdal.VersionInfo())"(返回 3130300 这类数字)、mvn -v、dotnet --version;本技能按 GDAL 3.13.3、Java 绑定 3.13.0 编写,低版本缺少新驱动与部分 SWIG 方法,回答里要说明差异。
  • 验证产物:写完后重新打开核对——python -c "from osgeo import gdal; ds=gdal.Open('out.tif'); print(ds.GetDriver().ShortName, ds.RasterCount, ds.GetSpatialRef().GetAuthorityCode(None))";矢量用 ogrinfo -al -so out.gpkg 看要素数与字段;Python 一律先 gdal.UseExceptions(),否则错误被静默吞掉。
  • 语言选择:数据处理脚本优先 Python(ReadAsArray() 直通 NumPy);生产服务与嵌入式优先 C++;Java 注意用 java.util.Vector<String> 传选项;.NET 用 OSGeo.GDAL/OSGeo.OGR 命名空间,或 MaxRev 封装 + 对应平台运行时包。
  • 资源与轴序:Python 置 ds = None、C++ GDALClose()、Java .delete()、C# .Dispose() 之后才算落盘;GDAL 3+ 默认纬度在前,需要经度在前时用 SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER),轴序改错是坐标错位最常见的原因。
  • 安全与权限:以更新模式(gdal.GA_Update、GDALOpen(..., GA_Update))打开会直接改原文件;覆盖已有输出前先确认;安装 libgdal-dev、dotnet add package、写系统目录前先征得用户同意。

相关技能

参考资源

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Gdal Api AI skill do?

Use when programming against GDAL/OGR in C, C++, Python, Java, or .NET — raster/vector I/O, gdal.UseExceptions, OGRSpatialReference transforms, gdal.Translate / gdal.Warp, VRT/COG, or fixing "no driver registered" and UnsatisfiedLinkError; C++ gdal-config, Maven org.gdal:gdal 3.13.0, NuGet MaxRev.Gdal.Core.

Why use Gdal Api on TypingMind?

Because you install it once and use it with any model. Gdal Api is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Gdal Api in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/znlgis/opengis-skills/tree/main/gis/gdal-api. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Gdal Api?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Gdal Api?

As many as you like. As long as a model supports skills, you can use Gdal Api with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Gdal Api AI skill free?

Yes. It is published on GitHub by znlgis under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇