Geometry Api Java logo

Geometry Api Java

Community
znlgis
geometry-api-java

Use when working with Esri geometry types (Point, Polyline, Polygon, Envelope) in Java — GeometryEngine, com.esri.geometry:esri-geometry-api:2.2.4, WKT/WKB/GeoJSON/Esri JSON I/O, geodesic distance; also when GeometryEngine has no intersects or WKB method and you need OperatorFactoryLocal, or when 2.3.1 coordinates fail to resolve on Maven Central. Esri Geometry API for Java.

Overview

Publisherznlgis
Repositoryopengis-skills
Skill namegeometry-api-java
Stars
76
Forks
12
Bundled files
Instructions only
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.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

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

Installation

Install the Geometry Api Java 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/geometry-api-java
  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/geometry-api-java .claude/skills/geometry-api-java
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Geometry Api Java 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 Geometry Api Java 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 Geometry Api Java 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/Esri/geometry-api-java

官方文档: https://github.com/Esri/geometry-api-java/wiki

Maven Central: com.esri.geometry:esri-geometry-api

最新版本: 2.2.4(Maven Central,截至 2026-10);上游源码 2.3.1(2026-10-09),未发布到 Central

许可证: Apache-2.0

概述

Esri Geometry API for Java 是一个自包含的空间几何计算库,提供对二维和三维几何对象的创建、解析、序列化以及空间关系运算能力。它无需任何外部 GIS 依赖,可直接嵌入 Java 应用、Hadoop MapReduce、Hive UDF、Spark 等大数据处理框架中。


环境准备与快速集成

Maven

xml
<dependency>
  <groupId>com.esri.geometry</groupId>
  <artifactId>esri-geometry-api</artifactId>
  <version>2.2.4</version><!-- Maven Central 最新版;上游 2.3.1 尚未发布到 Central -->
</dependency>

Gradle

groovy
implementation 'com.esri.geometry:esri-geometry-api:2.2.4'

环境要求: JDK 1.7+;运行时依赖 jackson-core(JSON 处理)。

维护状态提示: Maven Central 上最新发布版本仍是 2.2.4(2020-09);上游仓库已发布 2.3.1(2026-10),但尚未发布到 Maven Central(可从 GitHub Releases 获取构建产物)。若需活跃维护的几何库,新项目建议优先选用 JTS(Java)或 NetTopologySuite(.NET)。


核心 API 一览

类包用途
GeometryEnginecom.esri.core.geometry推荐入口——提供几何操作的静态便捷方法
OperatorFactoryLocalcom.esri.core.geometry算子工厂,适用于高性能批量处理
SpatialReferencecom.esri.core.geometry空间参考 / 坐标系(通过 WKID 或 WKT 创建)
MapGeometrycom.esri.core.geometry将 Geometry 与 SpatialReference 打包在一起
Pointcom.esri.core.geometry点(0 维)
MultiPointcom.esri.core.geometry多点集合(0 维)
Polylinecom.esri.core.geometry折线 / 路径集合(1 维)
Polygoncom.esri.core.geometry面 / 环集合(2 维)
Envelopecom.esri.core.geometry外接矩形(2 维)

几何对象创建

java
import com.esri.core.geometry.*;

// 点
Point pt = new Point(116.4, 39.9);          // 2D
Point pt3d = new Point(116.4, 39.9, 50.0);  // 3D

// 折线
Polyline line = new Polyline();
line.startPath(0, 0);
line.lineTo(10, 10);
line.lineTo(20, 0);

// 面
Polygon polygon = new Polygon();
polygon.startPath(0, 0);
polygon.lineTo(10, 0);
polygon.lineTo(10, 10);
polygon.lineTo(0, 10);
// 自动闭合

// 外接矩形
Envelope env = new Envelope(0, 0, 10, 10);

// 多点
MultiPoint mp = new MultiPoint();
mp.add(1, 2);
mp.add(3, 4);

空间参考

java
// 按 WKID 创建(WGS 84 = 4326)
SpatialReference srWGS84 = SpatialReference.create(4326);

// 按 WKT 字符串创建
SpatialReference srCustom = SpatialReference.create("GEOGCS[\"GCS_WGS_1984\",...]]");

// 与几何对象绑定
MapGeometry mapGeom = new MapGeometry(pt, srWGS84);

空间操作(通过 GeometryEngine)

集合运算

java
SpatialReference sr = SpatialReference.create(4326);

// 缓冲区(返回 Polygon)
Polygon buffered = GeometryEngine.buffer(point, sr, 100.0);

// 交集
Geometry inter = GeometryEngine.intersect(polygon1, polygon2, sr);

// 合并
Geometry united = GeometryEngine.union(new Geometry[]{poly1, poly2, poly3}, sr);

// 差集
Geometry diff = GeometryEngine.difference(polygon1, polygon2, sr);

// 对称差
Geometry symDiff = GeometryEngine.symmetricDifference(geom1, geom2, sr);

// 裁剪(按矩形)
Geometry clipped = GeometryEngine.clip(geometry, envelope, sr);

// 切割(用折线切割面或线)
Geometry[] parts = GeometryEngine.cut(polygon, cuttingLine, sr);

距离与邻近

java
double dist = GeometryEngine.distance(geom1, geom2, sr);

空间关系判断

java
boolean eq   = GeometryEngine.equals(g1, g2, sr);
boolean wn   = GeometryEngine.within(point, polygon, sr);
boolean ct   = GeometryEngine.contains(polygon, point, sr);
// 相交判断:GeometryEngine 未提供 intersects,需通过算子调用
boolean ix   = OperatorIntersects.local().execute(g1, g2, sr, null);
boolean dj   = GeometryEngine.disjoint(g1, g2, sr);
boolean tc   = GeometryEngine.touches(g1, g2, sr);
boolean cr   = GeometryEngine.crosses(line, polygon, sr);
boolean ol   = GeometryEngine.overlaps(poly1, poly2, sr);

// DE-9IM 关系矩阵
boolean rel  = GeometryEngine.relate(g1, g2, sr, "T*F**FFF*");

几何分析

java
// 凸包
Geometry hull = GeometryEngine.convexHull(geometry);

// 简化
Geometry simplified = GeometryEngine.simplify(geometry, sr);

// 泛化(简化顶点;GeometryEngine 未提供,使用算子)
Geometry generalized = OperatorGeneralize.local().execute(geometry, maxDeviation, true, null);

// 质心(GeometryEngine 无 getLabelPoint;标注点可用质心近似)
Point2D centroid = OperatorCentroid2D.local().execute(polygon, null);

大地测量(椭球面计算)

java
// 两点间大地距离(WGS84 椭球,单位米)——应用层公开的大地测量 API
double meters = GeometryEngine.geodesicDistanceOnWGS84(beijing, shanghai);

说明: 大地测量缓冲区 / 面积 / 长度的算子在库内部注册(Operator.Type.GeodesicBuffer、GeodeticArea、GeodeticLength),但其算子类在 2.2.4/2.3.x 中未对外公开(编译期不可引用)。应用层可直接使用的公开大地测量 API 为 GeometryEngine.geodesicDistanceOnWGS84();需要椭球面面积 / 长度 / 缓冲区时,建议改用 JTS / GeoTools 或 ArcGIS API。


格式转换

JSON(Esri JSON)

java
// 导入
MapGeometry mg = GeometryEngine.jsonToGeometry(jsonString);
Geometry geom = mg.getGeometry();
SpatialReference sr = mg.getSpatialReference();

// 导出(附带 WKID)
String json = GeometryEngine.geometryToJson(4326, geometry);

GeoJSON

java
// 导入
MapGeometry mg = GeometryEngine.geoJsonToGeometry(geoJsonString, 0, Geometry.Type.Unknown);

// 导出
String geoJson = GeometryEngine.geometryToGeoJson(geometry);

WKT(Well-Known Text)

java
// 导入
Geometry geom = GeometryEngine.geometryFromWkt(
    "POLYGON((0 0,10 0,10 10,0 10,0 0))",
    0,
    Geometry.Type.Polygon
);

// 导出
String wkt = GeometryEngine.geometryToWkt(geometry, 0);

WKB(Well-Known Binary)

java
OperatorFactoryLocal factory = OperatorFactoryLocal.getInstance();

// 导入(GeometryEngine 未提供 WKB 方法,使用算子)
OperatorImportFromWkb importer =
    (OperatorImportFromWkb) factory.getOperator(Operator.Type.ImportFromWkb);
Geometry geom = importer.execute(0, Geometry.Type.Unknown, ByteBuffer.wrap(wkbBytes), null);

// 导出
OperatorExportToWkb exporter =
    (OperatorExportToWkb) factory.getOperator(Operator.Type.ExportToWkb);
ByteBuffer wkb = exporter.execute(0, geometry, null);

Esri Shape

java
// 导入
Geometry geom = GeometryEngine.geometryFromEsriShape(byteBuffer, Geometry.Type.Polygon);

// 导出
byte[] shape = GeometryEngine.geometryToEsriShape(geometry);

高级用法:Operator 直接调用

当需要批量处理大量几何对象时,使用 OperatorFactoryLocal 获取算子并配合 GeometryCursor 可获得更好的性能:

java
OperatorFactoryLocal factory = OperatorFactoryLocal.getInstance();
OperatorBuffer bufferOp = (OperatorBuffer) factory.getOperator(Operator.Type.Buffer);

// 使用 SimpleGeometryCursor 包装输入
SimpleGeometryCursor inputCursor = new SimpleGeometryCursor(geometryArray);
double[] distances = {100.0};
GeometryCursor resultCursor = bufferOp.execute(inputCursor, sr, distances, false, null);

// 逐个取出结果
Geometry result;
while ((result = resultCursor.next()) != null) {
    // 处理每个缓冲区结果
}

几何类型判断

java
Geometry.Type type = geometry.getType();

switch (type) {
    case Point:      Point p = (Point) geometry; break;
    case Polygon:    Polygon pg = (Polygon) geometry; break;
    case Polyline:   Polyline pl = (Polyline) geometry; break;
    case MultiPoint: MultiPoint mp = (MultiPoint) geometry; break;
    case Envelope:   Envelope ev = (Envelope) geometry; break;
}

// 按维度判断
boolean isPoint  = Geometry.isPoint(type.value());
boolean isLinear = Geometry.isLinear(type.value());
boolean isArea   = Geometry.isArea(type.value());

顶点属性(Z / M / ID)

java
// 检查属性
geometry.hasZ();
geometry.hasM();
geometry.hasID();

// 添加属性
geometry.addAttribute(VertexDescription.Semantics.Z);
geometry.addAttribute(VertexDescription.Semantics.M);

典型工作流:WKT 解析 → 空间运算 → GeoJSON 输出

java
import com.esri.core.geometry.*;

// 1. 解析输入几何(WKT)
Geometry polygon = GeometryEngine.geometryFromWkt(
    "POLYGON((0 0,10 0,10 10,0 10,0 0))",
    0,
    Geometry.Type.Polygon
);

SpatialReference sr = SpatialReference.create(4326);

// 2. 缓冲区分析(GeometryEngine.buffer 返回 Polygon)
Polygon buffered = GeometryEngine.buffer(polygon, sr, 2.0);

// 3. 相交判断(算子调用)
boolean hit = OperatorIntersects.local().execute(buffered, new Point(5, 5), sr, null);

// 4. 导出 GeoJSON
if (hit) {
    String geoJson = GeometryEngine.geometryToGeoJson(buffered);
    System.out.println(geoJson);
}

典型应用场景

场景关键方法
地理围栏 / 点在面内判断GeometryEngine.contains() 或 within()
计算两点距离GeometryEngine.distance();经纬度点用 geodesicDistanceOnWGS84()
创建缓冲区(如 POI 周边范围)GeometryEngine.buffer()(平面缓冲区)
面求交 / 叠加分析GeometryEngine.intersect() / union() / difference()
坐标格式互转jsonToGeometry() / geometryToGeoJson() / geometryFromWkt() 等
几何有效性检查与修复GeometryEngine.simplify()
Hadoop / Spark 空间处理搭配 Operator + GeometryCursor 批量处理

常见问题

问题解决
空间运算结果异常确保所有几何对象使用相同的 SpatialReference
导入的几何拓扑无效用 GeometryEngine.simplify() 规范化后再参与运算
经纬度坐标下长度/面积失真平面算子在投影坐标下使用;经纬度距离用 geodesicDistanceOnWGS84()(椭球面积/长度算子未公开)
找不到 WKB / intersects / generalize 方法这些能力通过算子调用(OperatorImportFromWkb、OperatorIntersects、OperatorGeneralize 等)
批量处理性能差使用 OperatorFactoryLocal + GeometryCursor 批量执行,避免逐个调用静态方法
多线程共享 Operator 出错GeometryEngine 静态方法线程安全;Operator 实例非线程安全,不要跨线程复用

AI 使用建议

  • 执行环境:先 mvn -v 与 java -version 确认工具链(JDK 8+ 即可编译,建议 17/21 运行),Windows 上用 PowerShell 执行;%JAVA_HOME%/JAVA_HOME 与 mvn 实际使用的 JDK 可能不同,报 Unsupported class file major version 时按 mvn -v 显示的 JDK 判断。
  • 依赖坐标:com.esri.geometry:esri-geometry-api:2.2.4 是 Maven Central 最新(2020-09 发布);上游 2.3.1(2026-10-09)未发布到 Central。先 mvn dependency:get -Dartifact=com.esri.geometry:esri-geometry-api:2.2.4 确认可解析,解析失败时报告“依赖不可下载”,不要自行改成 2.3.1 或别处坐标。
  • 离线与网络:首次 mvn 会拉依赖,无网或私服缺包时报 Could not resolve dependencies;不要为绕过它去改 settings.xml、加未知仓库或降级版本,先向用户要可用镜像。
  • 验证产物:写最小 main(或 JUnit)断言三件事——geometryFromWkt → geometryToWkt 往返等价、GeometryEngine.buffer(poly, sr, 2.0) 后 getEnvelope() 向外扩张、geometryToGeoJson 能被 geoJsonToGeometry 重新读入;mvn -q -DskipTests package 只证明能编译,不代表几何正确。
  • 编译期陷阱:GeometryEngine 没有 intersects 和 WKB 方法,分别用 OperatorIntersects.local().execute(a, b, sr, null) 与 OperatorImportFromWkb/OperatorExportToWkb;面积/长度用 geometry.calculateArea2D() / calculateLength2D(),不要去找 getArea()。
  • 坐标与线程:参与运算的几何必须带同一 SpatialReference;GeometryEngine 静态方法可并发调用,Operator 实例非线程安全,批量时用 OperatorFactoryLocal + GeometryCursor 并每线程持有自己的算子。
  • 安全与权限:mvn 会写 ~/.m2 与工作区 target/,属预期行为;执行 mvn install/deploy、改动共享 settings.xml 或写入系统目录前先征得用户同意。

相关技能

参考资源

Frequently asked questions

What does the Geometry Api Java AI skill do?

Use when working with Esri geometry types (Point, Polyline, Polygon, Envelope) in Java — GeometryEngine, com.esri.geometry:esri-geometry-api:2.2.4, WKT/WKB/GeoJSON/Esri JSON I/O, geodesic distance; also when GeometryEngine has no intersects or WKB method and you need OperatorFactoryLocal, or when 2.3.1 coordinates fail to resolve on Maven Central. Esri Geometry API for Java.

Why use Geometry Api Java on TypingMind?

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

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

Which AI models can use Geometry Api Java?

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 Geometry Api Java?

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

Is the Geometry Api Java 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 👇