Logotipo de Geometry Api Java

Geometry Api Java

Comunidad
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.

Descripción general

Editorznlgis
Repositorioopengis-skills
Nombre de la habilidadgeometry-api-java
Estrellas
76
Forks
12
Archivos incluidos
Solo instrucciones
LicenciaMIT
Enlaces
  • Instrucciones en Markdown

    Un archivo SKILL.md que el modelo carga cuando lo necesita, de modo que solo consume tokens cuando una petición es realmente relevante.

  • Funciona con cualquier LLM

    Las habilidades de IA están en Markdown, no en código específico de un proveedor, por lo que funcionan con GPT, Claude, Gemini, Grok o un modelo local.

  • Todo en las instrucciones

    Todo lo que necesita el modelo está en las instrucciones: no hay archivos adicionales que sincronizar.

  • Código abierto

    Publicada por znlgis en GitHub. Revisa el contenido original antes de instalarla.

Instalación

Instala la habilidad de IA Geometry Api Java en TypingMind para usarla con cualquier LLM, o añádela a otro agente que lea SKILL.md.

1

Instalar en TypingMind

TypingMind instala una habilidad directamente desde su carpeta de GitHub: lee SKILL.md, empaqueta los archivos de recursos y guarda el resultado localmente.

  1. Abre la aplicación y ve a Plugins → Habilidades.
  2. Elige «Instalar desde GitHub».
  3. Pega la URL de la carpeta de la habilidad que se muestra a continuación y confirma.
    https://github.com/znlgis/opengis-skills/tree/main/gis/geometry-api-java
  4. Activa la habilidad en cada chat en el que quieras tenerla disponible.
Plugins → Habilidades → Añadir habilidad → Desde URL de GitHub; después, pega la URL de la carpeta y pulsa Continuar.
2

Instalar en otro agente

Cualquier agente que lea el formato Agent Skills puede usar esta habilidad: copia la carpeta en el directorio de habilidades de ese 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/geometry-api-java .claude/skills/geometry-api-java
Reinicia Claude Code después de copiarla para que detecte la nueva habilidad.

Úsala en TypingMind

Activa Geometry Api Java en cualquier chat de TypingMind y el modelo se encargará del resto. Su nombre y descripción se incluyen en el prompt del sistema y, en cuanto una petición es relevante, el modelo carga las instrucciones completas por sí solo. No tienes que invocarla manualmente y no consume tokens hasta que se utiliza.

El modelo carga Geometry Api Java automáticamente en cuanto una petición es relevante para esa habilidad.

Funciona con cualquier modelo de IA

Las habilidades de IA son instrucciones en Markdown, no código específico de un proveedor, por lo que Geometry Api Java no está vinculada al modelo para el que se creó. Instálala una sola vez en TypingMind y úsala con GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama o un modelo local que ejecutes tú, todo con tus propias claves API.

  • Se carga solo cuando se necesita

    El prompt del sistema solo incluye el nombre y la descripción. Las instrucciones se cargan con la primera petición relevante, por lo que una habilidad que no se usa no supone ningún coste.

  • Cambia de modelo durante el chat

    Como la habilidad contiene instrucciones y no código, cambiar de modelo no impide que funcione: el nuevo modelo lee el mismo archivo SKILL.md.

Instrucciones de la habilidad

Este es el contenido de SKILL.md que carga el modelo. Léelo antes de instalar la habilidad: contiene instrucciones que tu modelo seguirá.

项目地址: 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 或写入系统目录前先征得用户同意。

相关技能

参考资源

Preguntas frecuentes

¿Qué hace la habilidad de IA 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.

¿Por qué usar Geometry Api Java en TypingMind?

Porque la instalas una vez y la usas con cualquier modelo. Geometry Api Java está escrita en Markdown, no en código específico de un proveedor, por lo que la misma habilidad funciona con GPT-5, Claude, Gemini, Grok o un modelo local, y puedes cambiar de modelo en mitad del chat sin que deje de funcionar. TypingMind utiliza tus propias claves API, de modo que pagas directamente a los proveedores en lugar de pagar una suscripción por puesto, y tus habilidades y chats permanecen en tu propio almacenamiento.

¿Cómo instalo Geometry Api Java en TypingMind?

Abre Plugins → Habilidades → Instalar desde GitHub en TypingMind y pega https://github.com/znlgis/opengis-skills/tree/main/gis/geometry-api-java. TypingMind lee su archivo SKILL.md y la instala como una habilidad que puedes activar en cada chat.

¿Qué modelos de IA pueden usar Geometry Api Java?

Cualquier modelo que conectes en TypingMind. Las habilidades de IA son instrucciones en Markdown, no código específico de un proveedor, por lo que GPT, Claude, Gemini, Grok y los modelos locales pueden cargar esta habilidad cuando una solicitud se corresponda con ella.

¿Con cuántos modelos de IA puedo usar Geometry Api Java?

Con tantos como quieras. Siempre que un modelo admita habilidades, puedes usar Geometry Api Java con él: GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama y muchos más, todos en TypingMind con tus propias claves API.

¿Es gratuita la habilidad de IA Geometry Api Java?

Sí. znlgis la ha publicado en GitHub bajo la licencia MIT. Solo pagas a tu proveedor de IA por los tokens que utilizas.

¿Qué son las habilidades de IA?

Una habilidad de IA es un conjunto de instrucciones reutilizables que enseña a un modelo de IA a realizar una tarea concreta. Sigue el formato abierto Agent Skills: un archivo SKILL.md con un nombre y una descripción, además de los scripts, plantillas o archivos de referencia que pueda necesitar el modelo. El modelo solo lee las instrucciones cuando tu solicitud se corresponde con la habilidad, por lo que una habilidad instalada no supone ningún coste hasta que se utiliza.

¿En qué se diferencian las habilidades de IA de los plugins o los servidores MCP?

Un plugin o un servidor MCP proporciona al modelo nuevas herramientas que puede invocar: código que se ejecuta en algún lugar y devuelve un resultado. En cambio, una habilidad de IA aporta conocimientos y procedimientos al modelo: cómo abordar una tarea, qué pasos seguir y qué se considera un buen resultado. Las habilidades son instrucciones en Markdown, por lo que no necesitan servidor, clave API ni entorno de ejecución, y funcionan con cualquier modelo.

Ver todos

Crea ya tu propio espacio de trabajo IA

Suscríbete a nuestro boletín para recibir avisos sobre nuevas funciones y próximos sorteos 👇