Jts 标志

Jts

社区
znlgis
jts

Use when doing precise 2D computational geometry in Java with org.locationtech.jts:jts-core 1.20.0 — GeometryFactory construction, contains/intersects predicates, overlay via OverlayNGRobust, buffer, STRtree and PreparedGeometry speedups, WKT/WKB/GeoJSON I/O, and fixing TopologyException or unclosed rings.

概览

发布者znlgis
代码仓库opengis-skills
技能名称jts
星标数
76
复刻数
12
附带文件
1
许可协议MIT
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 1 个附带文件

    模型执行任务时可读取的脚本、模板和参考资料。这些文件为只读文件,绝不会被执行。

  • 开源

    由 znlgis 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Jts AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/znlgis/opengis-skills/tree/main/gis/jts
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

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/jts .claude/skills/jts
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Jts,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Jts。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Jts 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

项目地址: https://github.com/locationtech/jts

Maven Central: org.locationtech.jts:jts-core

最新版本: 1.20.0(截至 2026-10,Maven Central)

许可证: Eclipse Public License 2.0 / Eclipse Distribution License 1.0(BSD 风格)

Javadoc: https://locationtech.github.io/jts/javadoc

概述

JTS Topology Suite(简称 JTS)是 LocationTech 项目组下的开源 Java 二维矢量几何库,是 GeoTools、GeoServer 等众多开源 GIS 项目的几何计算核心。它提供:

  • 几何对象模型:Point、LineString、Polygon、MultiPoint、MultiLineString、MultiPolygon、GeometryCollection
  • 空间关系判断:equals、contains、within、intersects、touches、crosses、overlaps、disjoint、relate(DE-9IM)
  • 集合运算:intersection、union、difference、symDifference、buffer
  • 几何分析:convexHull、centroid、area、length、distance、isValid、simplify
  • 线性参考:沿线距离定位、线上插值
  • 空间索引:STRtree、Quadtree,加速批量空间查询
  • 格式读写:WKT、WKB、GeoJSON

环境要求: JDK 8+


环境准备与快速集成

Maven

xml
<properties>
    <jts.version>1.20.0</jts.version><!-- Maven Central 最新稳定版;列表见 https://central.sonatype.com/artifact/org.locationtech.jts/jts-core -->
</properties>

<dependency>
    <groupId>org.locationtech.jts</groupId>
    <artifactId>jts-core</artifactId>
    <version>${jts.version}</version>
</dependency>

如需 GeoJSON 等 I/O 支持(注意 groupId 是 org.locationtech.jts.io,与 jts-core 的 org.locationtech.jts 不同):

xml
<dependency>
    <groupId>org.locationtech.jts.io</groupId>
    <artifactId>jts-io-common</artifactId>
    <version>${jts.version}</version>
</dependency>

jts-io-common 的 GeoJsonWriter 在运行期还依赖 com.googlecode.json-simple:json-simple(Maven/Gradle 会自动带入);手工拼 classpath 时漏掉它会在写出 GeoJSON 时抛 NoClassDefFoundError: org/json/simple/JSONAware。

Gradle

groovy
implementation 'org.locationtech.jts:jts-core:1.20.0'
implementation 'org.locationtech.jts.io:jts-io-common:1.20.0'

项目模块一览

模块artifactId用途
jts-corejts-core(推荐)核心——几何模型、算法、空间操作、索引
jts-io-commonjts-io-common通用 I/O:WKT、WKB、GeoJSON 读写
jts-io-orajts-io-oraOracle Spatial SDO_GEOMETRY 读写——源码模块,需 -Pall(oracle profile)本地构建,未发布到 Maven Central
jts-io-sdejts-io-sdeArcSDE 几何读写——源码保留,构建中已注释禁用,无发布产物

核心类一览

类包用途
GeometryFactoryorg.locationtech.jts.geom推荐入口——创建所有几何对象的工厂
Geometryorg.locationtech.jts.geom几何抽象基类,提供空间操作与关系判断方法
Pointorg.locationtech.jts.geom点(0 维)
LineStringorg.locationtech.jts.geom线串(1 维)
LinearRingorg.locationtech.jts.geom闭合线环(用于构建 Polygon)
Polygonorg.locationtech.jts.geom面(2 维,含外环与可选内环)
MultiPointorg.locationtech.jts.geom多点集合
MultiLineStringorg.locationtech.jts.geom多线集合
MultiPolygonorg.locationtech.jts.geom多面集合
GeometryCollectionorg.locationtech.jts.geom任意几何集合
Coordinateorg.locationtech.jts.geom坐标值(x, y, z)
Envelopeorg.locationtech.jts.geom外接矩形(MBR)
PrecisionModelorg.locationtech.jts.geom坐标精度模型
WKTReaderorg.locationtech.jts.ioWKT 格式解析
WKTWriterorg.locationtech.jts.ioWKT 格式输出
WKBReaderorg.locationtech.jts.ioWKB 格式解析
WKBWriterorg.locationtech.jts.ioWKB 格式输出
GeoJsonReaderorg.locationtech.jts.io.geojsonGeoJSON 解析
GeoJsonWriterorg.locationtech.jts.io.geojsonGeoJSON 输出
STRtreeorg.locationtech.jts.index.strtreeR-tree 空间索引(批量加载,查询高效)
Quadtreeorg.locationtech.jts.index.quadtree四叉树空间索引(支持动态插入删除)
PreparedGeometryorg.locationtech.jts.geom.prep预处理几何,加速重复空间关系判断
PreparedGeometryFactoryorg.locationtech.jts.geom.prep创建 PreparedGeometry 的工厂
BufferOporg.locationtech.jts.operation.buffer缓冲区运算(可精细控制端头、连接样式)
OverlayNGRobustorg.locationtech.jts.operation.overlayng鲁棒叠加运算(推荐使用的新一代叠加引擎)
TopologyPreservingSimplifierorg.locationtech.jts.simplify保持拓扑的几何简化
DouglasPeuckerSimplifierorg.locationtech.jts.simplifyDouglas-Peucker 几何简化
IsValidOporg.locationtech.jts.operation.valid几何有效性检测
LengthIndexedLineorg.locationtech.jts.linearref按长度进行线性参考
LocationIndexedLineorg.locationtech.jts.linearref按位置进行线性参考

几何对象创建

java
import org.locationtech.jts.geom.*;

GeometryFactory gf = new GeometryFactory();

// 点
Point point = gf.createPoint(new Coordinate(116.4, 39.9));

// 带 Z 值的点
Point point3d = gf.createPoint(new Coordinate(116.4, 39.9, 50.0));

// 线串
LineString line = gf.createLineString(new Coordinate[]{
    new Coordinate(0, 0),
    new Coordinate(10, 10),
    new Coordinate(20, 0)
});

// 线环(必须闭合)
LinearRing ring = gf.createLinearRing(new Coordinate[]{
    new Coordinate(0, 0), new Coordinate(10, 0),
    new Coordinate(10, 10), new Coordinate(0, 10),
    new Coordinate(0, 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)
});

// 面(带洞)
LinearRing shell = gf.createLinearRing(new Coordinate[]{
    new Coordinate(0, 0), new Coordinate(20, 0),
    new Coordinate(20, 20), new Coordinate(0, 20),
    new Coordinate(0, 0)
});
LinearRing hole = gf.createLinearRing(new Coordinate[]{
    new Coordinate(5, 5), new Coordinate(15, 5),
    new Coordinate(15, 15), new Coordinate(5, 15),
    new Coordinate(5, 5)
});
Polygon polygonWithHole = gf.createPolygon(shell, new LinearRing[]{hole});

// 多点
MultiPoint multiPoint = gf.createMultiPointFromCoords(new Coordinate[]{
    new Coordinate(1, 2), new Coordinate(3, 4)
});

// 多线
MultiLineString multiLine = gf.createMultiLineString(new LineString[]{line});

// 多面
MultiPolygon multiPolygon = gf.createMultiPolygon(new Polygon[]{polygon});

// 几何集合
GeometryCollection gc = gf.createGeometryCollection(new Geometry[]{point, line, polygon});

空间关系、集合运算、几何分析、格式读写与空间索引的完整参考见 reference/geometry-operations.md

典型工作流:WKT → 缓冲区 → 空间判断 → GeoJSON

java
import org.locationtech.jts.geom.*;
import org.locationtech.jts.geom.prep.PreparedGeometry;
import org.locationtech.jts.geom.prep.PreparedGeometryFactory;
import org.locationtech.jts.io.WKTReader;
import org.locationtech.jts.io.geojson.GeoJsonWriter;

// 1. 从 WKT 解析输入几何
Geometry polygon = new WKTReader().read("POLYGON((0 0,10 0,10 10,0 10,0 0))");

// 2. 缓冲区分析并校验有效性
Geometry buffered = polygon.buffer(2.0);
boolean valid = buffered.isValid();

// 3. 点在面内判断(批量场景先做 PreparedGeometry 预处理)
PreparedGeometry prep = PreparedGeometryFactory.prepare(polygon);
boolean hit = prep.contains(new GeometryFactory().createPoint(new Coordinate(5, 5)));

// 4. 导出 GeoJSON
String geoJson = new GeoJsonWriter().write(buffered);

典型应用场景

场景关键类 / 方法
创建几何对象GeometryFactory.createPoint() / createLineString() / createPolygon()
地理围栏 / 点在面内判断Geometry.contains() / within(),高频场景用 PreparedGeometry
计算两个几何的距离Geometry.distance()
缓冲区分析Geometry.buffer() 或 BufferOp
面叠加分析(交并差)Geometry.intersection() / union() / difference()
鲁棒叠加运算OverlayNGRobust.overlay()
几何格式互转WKTReader / WKTWriter / WKBReader / WKBWriter / GeoJsonReader / GeoJsonWriter
批量空间查询加速STRtree / Quadtree
最近邻搜索STRtree.nearestNeighbour()
几何简化(抽稀)TopologyPreservingSimplifier / DouglasPeuckerSimplifier
几何有效性校验与修复IsValidOp / GeometryFixer
线性参考 / 沿线定位LengthIndexedLine / LocationIndexedLine
凸包计算Geometry.convexHull()
几何仿射变换AffineTransformation
数据库 WKB 交互WKBReader.hexToBytes() / WKBWriter.toHex()

常见问题

问题解决
无法直接 new Point(...) / 构造几何始终通过 GeometryFactory 的工厂方法创建几何对象
面数据无效(环未闭合)Polygon 外环与内环坐标数组首尾必须相同
经纬度顺序写反JTS 使用 (x, y) 即 (经度, 纬度),注意与 (纬度, 经度) 的系统区分
外部几何 isValid() 为 false用 GeometryFixer.fix() 修复后再参与运算
跨坐标系计算结果失真JTS 的 SRID 仅是元数据,所有计算在笛卡尔平面进行,不处理投影
批量空间查询慢用 STRtree 建索引;重复关系判断用 PreparedGeometry;大量合并用 UnaryUnionOp
多线程复用 Reader/Writer 出错GeometryFactory 与 Geometry 线程安全;WKTReader / WKTWriter 等非线程安全,每线程独立创建
叠加运算抛 TopologyException优先用 OverlayNGRobust.overlay(),比传统叠加引擎更鲁棒
写 GeoJSON 抛 NoClassDefFoundError: org/json/simple/JSONAware手工 classpath 缺 json-simple,用 Maven/Gradle 引入 jts-io-common 让其传递依赖生效
旧代码升级后 import 报错JTS 1.15+ 包名由 com.vividsolutions.jts 迁移为 org.locationtech.jts

AI 使用建议

  • 本技能的组织:主文件给高频用法,完整参数表与高级示例在 reference/geometry-operations.md,需要时再展开;示例工程与生成的数据写到工作目录,不要改动技能目录本身。
  • 执行环境:命令在终端 / shell 中执行;JTS 只依赖 jts-core,Maven Central 直接可解析,不需要额外仓库,JDK 8+ 即可。
  • 先探测版本:mvn dependency:tree -Dincludes=org.locationtech.jts 确认解析到 1.20.0;同时确认 classpath 里没有遗留的 com.vividsolutions.jts 旧包。
  • 验证产物:mvn -q test,或最小 main 做 WKT 往返 + geom.isValid() + buffer(0) 断言;导出 GeoJSON 后用 GeoJsonReader 读回比对坐标数,别只看日志。
  • 失败信号:TopologyException 改用 OverlayNGRobust.overlay();isValid() 为 false 先 GeometryFixer.fix();结果为空多半是把坐标写成了 (lat, lon)。
  • 注意事项:SRID 在 JTS 里只是元数据、计算全在笛卡尔平面,跨投影需自己先转换;WKTReader/WKTWriter 非线程安全,不要多线程共享。
  • 性能验证:批量判断用 PreparedGeometry 前后各计时一次(System.nanoTime()),用数据证明优化有效,别凭感觉。

相关技能

参考资源

附带文件

技能加载后,模型会按需读取这些文件。它们仅作为可读文件提供,绝不会被执行。

常见问题

Jts AI 技能有什么作用?

Use when doing precise 2D computational geometry in Java with org.locationtech.jts:jts-core 1.20.0 — GeometryFactory construction, contains/intersects predicates, overlay via OverlayNGRobust, buffer, STRtree and PreparedGeometry speedups, WKT/WKB/GeoJSON I/O, and fixing TopologyException or unclosed rings.

为什么在 TypingMind 中使用 Jts?

因为您只需安装一次,就能搭配任何模型使用。Jts 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Jts?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/znlgis/opengis-skills/tree/main/gis/jts。TypingMind 会读取其中的 SKILL.md,打包相关文件,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Jts?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Jts 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Jts 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Jts AI 技能免费吗?

是的。znlgis 已在 GitHub 上根据 MIT 许可证发布了该技能。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇