Geotools logo

Geotools

Community
znlgis
geotools

Use when building Java GIS apps on GeoTools 35.2 (JDK 17) — org.geotools:gt-main / gt-shapefile / gt-geopkg / gt-epsg-hsql from repo.osgeo.org (not Maven Central), CQL/ECQL filters, CRS.decode plus JTS.transform reprojection, StreamingRenderer PNG output, and disposing DataStore/SimpleFeatureIterator.

Overview

Publisherznlgis
Repositoryopengis-skills
Skill namegeotools
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 Geotools 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/geotools
  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/geotools .claude/skills/geotools
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Geotools 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 Geotools 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 Geotools 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/geotools/geotools

Maven GroupId: org.geotools

最新版本: 35.2(2026-10-16,OSGeo Maven 仓库)

许可证: LGPL 2.1

官方文档: https://docs.geotools.org/

概述

GeoTools 是一个成熟、模块化的开源 Java GIS 工具库,由 OSGeo 基金会管理,广泛应用于 GeoServer、uDig 等知名 GIS 平台。它提供:

  • 矢量数据访问:Shapefile、GeoPackage、GeoJSON、PostGIS、Oracle Spatial、SQL Server 等
  • 栅格数据访问:GeoTIFF、NetCDF、ImageMosaic 等
  • 坐标参考系统 (CRS):基于 EPSG 数据库的投影定义与坐标转换
  • 空间查询与过滤:CQL / ECQL、OGC Filter 编码
  • 地图渲染:基于 SLD/SE 的制图样式与图片输出
  • OGC Web 服务:WMS / WFS / WCS 客户端
  • 几何运算:基于 JTS Topology Suite 的全套几何计算

环境要求: GeoTools 34+(当前 35.x)要求 JDK 17,35.x 官方构建文档另列出可选 JDK 21;更早分支的历史矩阵为 ≤28 用 JDK 8、29–33 用 JDK 11,具体以官方安装文档为准。

官方构建要求(实测 https://docs.geotools.org/stable/userguide/build/install/index.html):"Java Development Kit 17 (JDK 17)",可选 JDK 21;PR 同时用 JDK 17 与 21 测试。


环境准备与快速集成

Maven 仓库配置

GeoTools 发布在 OSGeo Maven 仓库,需在 pom.xml 中添加:

xml
<repositories>
    <repository>
        <id>osgeo</id>
        <name>OSGeo Release Repository</name>
        <url>https://repo.osgeo.org/repository/release/</url>
    </repository>
</repositories>

常用模块依赖

xml
<properties>
    <geotools.version>35.2</geotools.version><!-- 最新稳定版;版本列表见 https://geotools.org/ -->
</properties>

<dependencies>
    <!-- 核心 -->
    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-main</artifactId>
        <version>${geotools.version}</version>
    </dependency>
    <!-- Shapefile -->
    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-shapefile</artifactId>
        <version>${geotools.version}</version>
    </dependency>
    <!-- GeoTIFF 栅格 -->
    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-geotiff</artifactId>
        <version>${geotools.version}</version>
    </dependency>
    <!-- GeoPackage -->
    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-geopkg</artifactId>
        <version>${geotools.version}</version>
    </dependency>
    <!-- EPSG 坐标系数据库(HSQL 嵌入式) -->
    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-epsg-hsql</artifactId>
        <version>${geotools.version}</version>
    </dependency>
    <!-- PostGIS -->
    <dependency>
        <groupId>org.geotools.jdbc</groupId>
        <artifactId>gt-jdbc-postgis</artifactId>
        <version>${geotools.version}</version>
    </dependency>
    <!-- CQL 查询语言 -->
    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-cql</artifactId>
        <version>${geotools.version}</version>
    </dependency>
    <!-- 地图渲染 -->
    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-render</artifactId>
        <version>${geotools.version}</version>
    </dependency>
    <!-- GeoJSON 数据格式 -->
    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-geojson-core</artifactId>
        <version>${geotools.version}</version>
    </dependency>
</dependencies>

核心模块一览

模块artifactId用途
gt-maingt-main(推荐)核心接口与实现——Feature / DataStore / Filter
gt-apigt-api高层 API 接口定义(Feature、CRS、Filter 等)
gt-referencinggt-referencing坐标参考系统定义与转换
gt-epsg-hsqlgt-epsg-hsql嵌入式 EPSG 数据库(基于 HSQL)
gt-shapefilegt-shapefileShapefile 矢量读写
gt-geopkggt-geopkgGeoPackage 矢量 / 栅格读写
gt-geotiffgt-geotiffGeoTIFF 栅格读写
gt-coveragegt-coverage栅格覆盖(GridCoverage)处理
gt-cqlgt-cqlCQL / ECQL 查询语言解析
gt-rendergt-render地图渲染输出(PNG、SVG 等)
gt-jdbc-postgisgt-jdbc-postgisPostGIS 数据库连接
gt-geojson-coregt-geojson-coreGeoJSON 读写
gt-wmsgt-wmsOGC WMS 客户端
gt-wfs-nggt-wfs-ngOGC WFS 客户端
gt-processgt-process地理处理框架

核心类一览

类 / 接口包用途
DataStoreorg.geotools.data(推荐)矢量数据源的统一抽象入口
DataStoreFinderorg.geotools.data通过参数自动定位并创建 DataStore
FileDataStoreFinderorg.geotools.data快速打开单文件数据源(Shapefile 等)
SimpleFeatureTypeorg.opengis.feature.simple要素类型定义(字段名、类型、CRS)
SimpleFeatureorg.opengis.feature.simple单个矢量要素(属性 + 几何)
SimpleFeatureSourceorg.geotools.data.simple只读要素数据源
SimpleFeatureStoreorg.geotools.data.simple可读写要素数据源
SimpleFeatureCollectionorg.geotools.data.simple要素集合
SimpleFeatureBuilderorg.geotools.feature.simple构建 SimpleFeature 实例
SimpleFeatureTypeBuilderorg.geotools.feature.simple构建 SimpleFeatureType 定义
Geometryorg.locationtech.jts.geomJTS 几何基类(Point、LineString、Polygon 等)
GeometryFactoryorg.locationtech.jts.geom创建几何对象的工厂
JTSFactoryFinderorg.geotools.geometry.jtsGeoTools 推荐的 GeometryFactory 获取方式
JTSorg.geotools.geometry.jtsJTS 几何工具类(坐标转换、Envelope 转换等)
CRSorg.geotools.referencing.CRS(推荐)坐标参考系统工具类(解码 EPSG、查找转换)
CoordinateReferenceSystemorg.opengis.referencing.crsCRS 接口
MathTransformorg.opengis.referencing.operation坐标转换数学变换
Filterorg.opengis.filterOGC 过滤器接口
CQLorg.geotools.filter.text.cql2CQL 查询语言解析器
ECQLorg.geotools.filter.text.ecql扩展 CQL 解析器(支持更多语法)
Styleorg.geotools.stylingSLD 制图样式
SLDorg.geotools.styling.SLD快速创建简单样式的工具类
MapContentorg.geotools.map地图容器(管理图层集合)
FeatureLayerorg.geotools.map矢量图层
GridCoverage2Dorg.geotools.coverage.grid二维栅格覆盖数据
GeoTiffReaderorg.geotools.gce.geotiffGeoTIFF 读取器
GeoTiffWriterorg.geotools.gce.geotiffGeoTIFF 写入器
ReferencedEnvelopeorg.geotools.geometry.jts带 CRS 的矩形范围
DataUtilitiesorg.geotools.data数据工具类(类型创建、集合转换等)

矢量数据读取与写入的完整示例见 reference/vector-io.md

坐标参考系统 (CRS) 与坐标转换

java
import org.geotools.referencing.CRS;
import org.geotools.geometry.jts.JTS;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.operation.MathTransform;

// 解码 EPSG
CoordinateReferenceSystem wgs84 = CRS.decode("EPSG:4326");
CoordinateReferenceSystem webMercator = CRS.decode("EPSG:3857");
CoordinateReferenceSystem cgcs2000 = CRS.decode("EPSG:4490");

// 查找坐标转换
MathTransform transform = CRS.findMathTransform(wgs84, webMercator, true);

// 转换几何对象
Geometry projected = JTS.transform(originalGeometry, transform);

// 转换单个坐标
Coordinate source = new Coordinate(116.4, 39.9);
Coordinate target = JTS.transform(source, null, transform);

// 获取 CRS 的 EPSG 编码
Integer code = CRS.lookupEpsgCode(wgs84, false);

// 从 WKT 创建 CRS
CoordinateReferenceSystem custom = CRS.parseWKT("GEOGCS[...]");

空间查询与过滤(CQL / ECQL)

java
import org.geotools.filter.text.cql2.CQL;
import org.geotools.filter.text.ecql.ECQL;
import org.opengis.filter.Filter;

// 属性过滤
Filter nameFilter = CQL.toFilter("NAME = '北京'");
Filter popFilter = CQL.toFilter("POPULATION > 1000000");

// 空间过滤(BBOX)
Filter bboxFilter = CQL.toFilter(
    "BBOX(the_geom, 116.0, 39.0, 117.0, 40.0)"
);

// 空间关系
Filter containsFilter = CQL.toFilter(
    "CONTAINS(the_geom, POINT(116.4 39.9))"
);
Filter intersectsFilter = CQL.toFilter(
    "INTERSECTS(the_geom, POLYGON((116 39, 117 39, 117 40, 116 40, 116 39)))"
);

// 组合过滤(ECQL 支持更丰富语法)
Filter combined = ECQL.toFilter(
    "NAME LIKE '北%' AND POPULATION > 500000"
);

// 应用过滤查询
SimpleFeatureCollection filtered = featureSource.getFeatures(nameFilter);

几何操作(基于 JTS)

java
import org.locationtech.jts.geom.*;
import org.geotools.geometry.jts.JTSFactoryFinder;

GeometryFactory gf = JTSFactoryFinder.getGeometryFactory();

// 创建几何对象
Point point = gf.createPoint(new Coordinate(116.4, 39.9));
LineString line = gf.createLineString(new Coordinate[]{
    new Coordinate(0, 0), new Coordinate(10, 10), new Coordinate(20, 0)
});
Polygon polygon = gf.createPolygon(new Coordinate[]{
    new Coordinate(0, 0), new Coordinate(10, 0),
    new Coordinate(10, 10), new Coordinate(0, 10),
    new Coordinate(0, 0)  // 闭合
});

// 缓冲区
Geometry buffered = point.buffer(0.01);

// 空间关系
boolean contains = polygon.contains(point);
boolean intersects = line.intersects(polygon);
boolean within = point.within(polygon);

// 集合运算
Geometry union = polygon1.union(polygon2);
Geometry intersection = polygon1.intersection(polygon2);
Geometry difference = polygon1.difference(polygon2);
Geometry symDiff = polygon1.symDifference(polygon2);

// 几何属性
double area = polygon.getArea();
double length = line.getLength();
Point centroid = polygon.getCentroid();
Envelope env = polygon.getEnvelopeInternal();
double distance = point.distance(line);

// 凸包
Geometry convexHull = geometry.convexHull();

// 简化
import org.locationtech.jts.simplify.TopologyPreservingSimplifier;
Geometry simplified = TopologyPreservingSimplifier.simplify(geometry, 0.001);

// WKT 读写
import org.locationtech.jts.io.WKTReader;
import org.locationtech.jts.io.WKTWriter;
WKTReader wktReader = new WKTReader();
Geometry geom = wktReader.read("POINT (116.4 39.9)");
String wkt = new WKTWriter().write(geom);

栅格数据(GeoTIFF)与地图渲染的完整示例见 reference/raster-rendering.md GeoJSON 与 WKT/WKB 格式读写的完整示例见 reference/vector-io.md

典型工作流:读取 → 过滤 → 重投影

端到端示例(Java):打开 Shapefile → CQL 空间+属性过滤 → 重投影到 Web Mercator:

java
import org.geotools.data.*;
import org.geotools.data.simple.*;
import org.geotools.filter.text.cql2.CQL;
import org.geotools.referencing.CRS;
import org.geotools.geometry.jts.JTS;
import org.opengis.filter.Filter;
import org.opengis.referencing.operation.MathTransform;
import org.locationtech.jts.geom.Geometry;

// 1. 打开 Shapefile
FileDataStore store = FileDataStoreFinder.getDataStore(new File("cities.shp"));
SimpleFeatureSource source = store.getFeatureSource();

// 2. CQL 过滤(属性 + 空间条件)
Filter filter = CQL.toFilter(
    "POPULATION > 1000000 AND BBOX(the_geom, 116, 39, 117, 40)");
SimpleFeatureCollection features = source.getFeatures(filter);

// 3. 逐要素重投影(WGS84 → EPSG:3857)
MathTransform transform = CRS.findMathTransform(
    source.getSchema().getCoordinateReferenceSystem(),
    CRS.decode("EPSG:3857"), true);
try (SimpleFeatureIterator iter = features.features()) {
    while (iter.hasNext()) {
        SimpleFeature f = iter.next();
        Geometry projected = JTS.transform((Geometry) f.getDefaultGeometry(), transform);
        // 处理/写出 projected
    }
}
store.dispose();

写出 GeoJSON、创建 FeatureType 与写 Shapefile 的完整示例见 reference/vector-io.md。

典型应用场景

场景关键类 / 方法
读取 Shapefile 数据FileDataStoreFinder → SimpleFeatureSource.getFeatures()
读写 GeoPackageDataStoreFinder(dbtype=geopkg)→ SimpleFeatureStore
连接 PostGIS 数据库DataStoreFinder(dbtype=postgis)→ SimpleFeatureStore
读写 GeoJSONFeatureJSON.readFeatureCollection() / writeFeatureCollection()
坐标系转换(如 WGS84 → Web Mercator)CRS.decode() → CRS.findMathTransform() → JTS.transform()
属性查询CQL.toFilter("NAME = 'xxx'") → featureSource.getFeatures(filter)
空间查询(范围过滤)CQL.toFilter("BBOX(the_geom, ...)")
空间关系判断(包含、相交等)Geometry.contains() / intersects() / within()
缓冲区分析Geometry.buffer(distance)
面叠加分析(交集 / 合并 / 差集)Geometry.intersection() / union() / difference()
读取 GeoTIFF 栅格GeoTiffReader.read() → GridCoverage2D
地图渲染输出 PNGMapContent + StreamingRenderer.paint()
创建矢量要素并写入SimpleFeatureTypeBuilder → SimpleFeatureBuilder → SimpleFeatureStore
SLD 样式制图StyleFactory + PolygonSymbolizer / PointSymbolizer / LineSymbolizer

常见问题

问题解决
找不到 gt-* 依赖(无法解析)GeoTools 不在 Maven Central,必须在 pom.xml 配置 OSGeo 仓库(https://repo.osgeo.org/repository/release/)
CRS.decode() 抛出异常引入 gt-epsg-hsql(嵌入式)或 gt-epsg-wkt(轻量)模块提供 EPSG 数据库
经纬度顺序与预期相反GeoTools 默认遵循 EPSG 规范(纬度在前);CRS.decode("EPSG:4326", true) 强制经度在前
文件句柄泄漏 / 数据未写盘DataStore、Reader、Writer、MapContent 使用后必须 dispose();SimpleFeatureIterator 用 try-with-resources 关闭
多线程处理迭代器异常DataStore 线程安全可共享;SimpleFeatureIterator 非线程安全,每线程独立使用
DataStoreFinder.getDataStore() 返回 null确保对应模块 JAR 在 classpath(GeoTools 通过 Java SPI 自动发现工厂)
升级后包名报错GeoTools 20+ 使用 org.locationtech.jts(≤19 为 com.vividsolutions.jts)
大数据量查询慢用 Query 限制返回属性与空间范围,避免全量加载;PostGIS 建议开启 preparedStatements
Shapefile 中文乱码创建 ShapefileDataStore 后调用 store.setCharset(Charset.forName("GBK")) 设置编码

AI 使用建议

  • 本技能的组织:主文件给高频用法,完整参数表与高级示例在 reference/raster-rendering.md、reference/vector-io.md,需要时再展开;示例工程与生成的数据写到工作目录,不要改动技能目录本身。
  • 执行环境:命令在终端 / shell 中执行;先 java -version 与 mvn -v 确认 JDK 17,35.x 在 JDK 8/11 下编译即失败。
  • 先探测版本:mvn dependency:tree -Dincludes=org.geotools 确认解析到 35.2 且未被其他依赖压回旧版;pom.xml 里必须有指向 repo.osgeo.org/repository/release/ 的 <repository>。
  • 验证产物:mvn -q -DskipTests package 后跑最小读图层程序(FileDataStoreFinder → getFeatures() → 打印 count 与 CRS)或 mvn -q test;CRS.decode("EPSG:4326") 抛异常说明缺 gt-epsg-hsql。
  • 常见失败信号:getDataStore() 返回 null 或报找不到工厂,是 SPI 模块没进 classpath;出现 com.vividsolutions.jts 是包名没升级(GeoTools 20+ 用 org.locationtech.jts)。
  • 安全与权限:测试别全量加载要素到内存(用 Query 限制属性与 bbox);连接串/密码不要回显,对生产库批量写入前先向用户确认。
  • 按需读文件:本 SKILL 较长,先按章节标题定位,再按行区间分段读取,避免整篇占满上下文。

相关技能

参考资源

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 Geotools AI skill do?

Use when building Java GIS apps on GeoTools 35.2 (JDK 17) — org.geotools:gt-main / gt-shapefile / gt-geopkg / gt-epsg-hsql from repo.osgeo.org (not Maven Central), CQL/ECQL filters, CRS.decode plus JTS.transform reprojection, StreamingRenderer PNG output, and disposing DataStore/SimpleFeatureIterator.

Why use Geotools on TypingMind?

Because you install it once and use it with any model. Geotools 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 Geotools in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/znlgis/opengis-skills/tree/main/gis/geotools. 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 Geotools?

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 Geotools?

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

Is the Geotools 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 👇