Logo di Geotools

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.

Panoramica

Pubblicato daznlgis
Repositoryopengis-skills
Nome della skillgeotools
Stelle
76
Fork
12
File inclusi
2
LicenzaMIT
Link
  • Istruzioni in Markdown

    Un file SKILL.md che il modello carica quando serve, consumando token solo quando una richiesta è effettivamente pertinente.

  • Funziona con qualsiasi LLM

    Le skill IA sono in semplice Markdown, non in codice specifico di un fornitore, quindi funzionano con GPT, Claude, Gemini, Grok o un modello locale.

  • File inclusi: 2

    Script, template e riferimenti che il modello può leggere mentre lavora. I file sono di sola lettura e non vengono mai eseguiti.

  • Open source

    Pubblicata da znlgis su GitHub. Leggi i sorgenti prima di installarla.

Installazione

Installa la skill IA Geotools in TypingMind per usarla con qualsiasi LLM, oppure copiala in un altro agente in grado di leggere SKILL.md.

1

Installa in TypingMind

TypingMind installa una skill direttamente dalla sua cartella GitHub: legge SKILL.md, raccoglie i file delle risorse e salva il risultato in locale.

  1. Apri l'app e vai su Plugin → Skill.
  2. Scegli "Installa da GitHub".
  3. Incolla l'URL della cartella della skill riportato qui sotto e conferma.
    https://github.com/znlgis/opengis-skills/tree/main/gis/geotools
  4. Attiva la skill in ogni chat in cui vuoi averla a disposizione.
Plugin → Skill → Aggiungi skill → Da URL GitHub, poi incolla l'URL della cartella e premi Continua.
2

Installa in un altro agente

Qualsiasi agente che legge il formato Agent Skills può usare questa skill: copia la cartella della skill nella directory delle skill di quell'agente.

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
Dopo la copia, riavvia Claude Code per caricare la nuova skill.

Usala in TypingMind

Attiva Geotools in qualsiasi chat di TypingMind e al resto pensa il modello. Il nome e la descrizione della skill sono nel prompt di sistema e, non appena arriva una richiesta pertinente, il modello carica da solo le istruzioni complete: non devi mai richiamarla manualmente e non consuma token finché non viene effettivamente usata.

Il modello carica automaticamente Geotools non appena riceve una richiesta pertinente.

Funziona con qualsiasi modello IA

Le skill IA sono semplici istruzioni in Markdown, non codice specifico di un fornitore, quindi Geotools non è vincolata al modello per cui è stata scritta. Installala una sola volta in TypingMind e usala con GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama o un modello locale che esegui tu, sempre con le tue chiavi API.

  • Caricata solo quando serve

    Il prompt di sistema contiene solo il nome e la descrizione. Le istruzioni vengono recuperate alla prima richiesta pertinente, quindi una skill inutilizzata non costa nulla.

  • Cambia modello durante la chat

    Poiché la skill è composta da istruzioni e non da codice, continua a funzionare anche se cambi modello: il nuovo modello legge lo stesso file SKILL.md.

Istruzioni della skill

Questo è il contenuto di SKILL.md che il modello carica. Leggilo prima dell'installazione: una skill è un insieme di istruzioni che il tuo modello seguirà.

项目地址: 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 较长,先按章节标题定位,再按行区间分段读取,避免整篇占满上下文。

相关技能

参考资源

File inclusi

Il modello legge questi file quando servono, mentre la skill è caricata. Sono accessibili in sola lettura e non vengono mai eseguiti.

Domande frequenti

Cosa fa la skill IA 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.

Perché usare Geotools su TypingMind?

Perché la installi una volta e la usi con qualsiasi modello. Geotools è scritta in semplice Markdown anziché in codice specifico di un fornitore, quindi la stessa skill funziona con GPT-5, Claude, Gemini, Grok o un modello locale, e puoi cambiare modello durante la chat senza che la skill smetta di funzionare. TypingMind usa le tue chiavi API, quindi paghi direttamente i fornitori anziché un abbonamento per posto utente, e le tue skill e chat restano nel tuo spazio di archiviazione.

Come installo Geotools in TypingMind?

Apri Plugin → Skill → Installa da GitHub in TypingMind e incolla https://github.com/znlgis/opengis-skills/tree/main/gis/geotools. TypingMind legge il file SKILL.md, include i file associati e installa la skill, che puoi abilitare per ogni singola chat.

Quali modelli IA possono usare Geotools?

Qualsiasi modello che colleghi a TypingMind. Le skill IA sono semplici istruzioni in Markdown anziché codice specifico di un fornitore, quindi GPT, Claude, Gemini, Grok e i modelli locali possono tutti caricare questa skill quando una richiesta corrisponde al suo scopo.

Quanti modelli IA posso usare con Geotools?

Quanti ne vuoi. Se un modello supporta le skill, puoi usarlo con Geotools: GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama e molti altri, tutti su TypingMind con le tue chiavi API.

La skill IA Geotools è gratuita?

Sì. È pubblicata su GitHub da znlgis con licenza MIT. Paghi solo il tuo fornitore IA per i token che usi.

Cosa sono le skill IA?

Una skill IA è un pacchetto di istruzioni riutilizzabili che insegna a un modello IA come svolgere un'attività specifica. Segue il formato aperto Agent Skills: un file SKILL.md con un nome e una descrizione, più eventuali script, template o file di riferimento di cui il modello potrebbe aver bisogno. Il modello legge le istruzioni solo quando la tua richiesta corrisponde alla skill, quindi una skill installata non comporta costi finché non viene usata.

In cosa si differenziano le skill IA dai plugin o dai server MCP?

Un plugin o un server MCP fornisce a un modello nuovi strumenti da richiamare: codice che viene eseguito da qualche parte e restituisce un risultato. Una skill IA, invece, fornisce al modello conoscenze e procedure: come affrontare un'attività, quali passaggi seguire e quali caratteristiche deve avere un buon output. Le skill sono semplici istruzioni in Markdown, quindi non richiedono server, chiavi API né ambienti di esecuzione e funzionano con qualsiasi modello.

Elenco completo

Crea subito il tuo spazio di lavoro AI

Iscriviti alla nostra newsletter per ricevere aggiornamenti sulle nuove funzionalità e sulle prossime iniziative a premi 👇