Opengis Utils For Java 标志

Opengis Utils For Java

社区
znlgis
opengis-utils-for-java

Use when needing common GIS utilities in Java — OguLayerUtil layer read/write, GeometryUtil 60+ ops, CrsUtil CGCS2000 (EPSG:4490, 4502-4554), Shapefile/GeoJSON/FileGDB/PostGIS/land TXT I/O, topology validation; also for GDAL UnsatisfiedLinkError on gdal_jni, missing osgeo repo on GeoTools, or resolving com.znlgis.ogu4j:ogu4j:1.0.0 that is not on Maven Central. OGU4J.

概览

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

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

  • 兼容任何大语言模型

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

  • 1 个附带文件

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

  • 开源

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

安装

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

1

安装到 TypingMind

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

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/znlgis/opengis-skills/tree/main/gis/opengis-utils-for-java
  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/opengis-utils-for-java .claude/skills/opengis-utils-for-java
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

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

一旦请求与技能匹配,模型就会自动加载 Opengis Utils For Java。

兼容任何 AI 模型

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

  • 仅在需要时加载

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

  • 在聊天中切换模型

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

技能指令

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

项目地址: https://github.com/znlgis/opengis-utils-for-java

官方文档: https://github.com/znlgis/opengis-utils-for-java#readme

Maven 坐标: com.znlgis.ogu4j:ogu4j:1.0.0(截至 2026-10 尚未发布到 Maven Central,需从源码 mvn install 安装到本地仓库)

许可证: LGPL-2.1-or-later

概述

OGU4J (OpenGIS Utils for Java) is a unified Java GIS toolkit built on GeoTools, JTS, GDAL/OGR, and ESRI Geometry API. It provides:

  • A unified layer model (OguLayer) for reading/writing GIS data across formats
  • Geometry operations (60+ methods) via GeometryUtil
  • Dual-engine architecture (GeoTools pure-Java & GDAL native)
  • Coordinate reference system management (CGCS2000 built-in)

Java Version: 17+
Build Tool: Maven
Group ID: com.znlgis.ogu4j | Artifact ID: ogu4j | Version: 1.0.0


环境准备

bash
# 前置:JDK 17+ 与 Maven 3.8+
java -version
mvn -version

# 克隆并构建(安装到本地 Maven 仓库)
git clone https://github.com/znlgis/opengis-utils-for-java.git
cd opengis-utils-for-java
mvn install -DskipTests

在业务项目的 pom.xml 中引入依赖(GeoTools 依赖通过 osgeo 仓库解析):

xml
<repositories>
    <repository>
        <id>osgeo</id>
        <url>https://repo.osgeo.org/repository/release/</url>
    </repository>
</repositories>

<dependency>
    <groupId>com.znlgis.ogu4j</groupId>
    <artifactId>ogu4j</artifactId>
    <version>1.0.0</version>
</dependency>

环境要求: JDK 17+;GDAL 引擎需本地原生 GDAL 库(与 org.gdal:gdal 绑定版本 3.13.0 匹配);纯 GeoTools 引擎无需原生库。验证:mvn dependency:tree 中出现 com.znlgis.ogu4j:ogu4j:1.0.0,且代码中 import com.znlgis.ogu4j.datasource.OguLayerUtil; 可编译。


核心 API:包结构与入口类

text
com.znlgis.ogu4j
├── datasource/                  # High-level data I/O
│   ├── OguLayerUtil             # Primary entry point for reading/writing layers
│   └── GtTxtUtil                # National land TXT format support
├── engine/                      # GIS engine core
│   ├── GisEngine                # Engine interface
│   ├── GisEngineFactory         # Engine factory (auto-selects best engine)
│   ├── GeoToolsEngine           # GeoTools implementation (pure Java, always available)
│   ├── GdalEngine               # GDAL implementation (requires native GDAL)
│   ├── GeoToolsLayerReader/Writer  # GeoTools format I/O
│   ├── GdalLayerReader/Writer      # GDAL format I/O
│   ├── enums/                   # Enumerations
│   │   ├── DataFormatType       # SHP, GEOJSON, FILEGDB, POSTGIS, TXT, WKT, ESRIJSON, ARCSDE
│   │   ├── FieldDataType        # INTEGER, DOUBLE, STRING, BINARY, DATE, TIME, DATETIME, LONG
│   │   ├── GeometryType         # POINT, MULTIPOINT, LINESTRING, POLYGON, etc.
│   │   ├── GisEngineType        # GEOTOOLS, GDAL, AUTO
│   │   └── TopologyValidationErrorType
│   ├── io/                      # Reader/Writer interfaces
│   │   ├── LayerReader          # read(path, layerName, attributeFilter, spatialFilterWkt)
│   │   └── LayerWriter          # write(layer, path, layerName, options)
│   ├── model/
│   │   ├── layer/               # Core data model
│   │   │   ├── OguLayer         # Layer: name, wkid, geometryType, fields, features
│   │   │   ├── OguFeature       # Feature: id, geometry (WKT), attributes
│   │   │   ├── OguField         # Field definition: name, alias, dataType, length
│   │   │   ├── OguFieldValue    # Field value with type conversion methods
│   │   │   ├── OguCoordinate    # Coordinate point (x, y, z)
│   │   │   ├── OguFeatureFilter # Functional interface for filtering
│   │   │   └── OguLayerMetadata # Extended metadata (CRS, projection, etc.)
│   │   ├── DbConnBaseModel      # PostGIS connection configuration
│   │   ├── GdbGroupModel        # FileGDB structure
│   │   ├── TopologyValidationResult
│   │   └── SimpleGeometryResult
│   └── util/
│       ├── CrsUtil              # Coordinate system management & transformation
│       ├── GeotoolsUtil         # GeoTools feature filtering
│       ├── OgrUtil              # GDAL/OGR initialization & resource management
│       ├── PostgisUtil          # PostGIS connection helpers
│       ├── ShpUtil              # Shapefile encoding & field name handling
│       └── GdalCmdUtil          # GDAL command-line wrapper (ogrinfo)
├── geometry/
│   └── GeometryUtil             # 60+ geometry operation methods
├── exception/
│   ├── OguException             # Base checked exception
│   ├── DataSourceException      # Data source connection failures
│   ├── EngineNotSupportedException
│   ├── FormatParseException     # Format parsing failures
│   ├── LayerValidationException # Unchecked (RuntimeException)
│   └── TopologyException
└── utils/
    ├── ZipUtil                  # ZIP compress/decompress
    ├── EncodingUtil             # File encoding detection
    ├── SortUtil                 # Natural string sorting
    └── NumUtil                  # Number formatting (remove scientific notation)

常见任务快速参考(Quick Reference: Common Tasks)完整内容见 reference/common-tasks.md

数据格式支持矩阵

FormatDataFormatTypeGeoToolsGDALReadWriteNotes
ShapefileSHPYesYesYesYesField names limited to 10 chars
GeoJSONGEOJSONYesYesYesYes
FileGDBFILEGDBNoYesYesYesRequires GDAL native library
PostGISPOSTGISYesYesYesYesConnection string as path
National Land TXTTXTYesNoYesYesUse GtTxtUtil directly
WKTWKTYesNoYesNoGeometry-only format
ESRI JSONESRIJSONNoNoYes*No*Via GeometryUtil conversion

数据模型参考

OguLayer(核心)

PropertyTypeDescription
nameStringLayer name
aliasStringLayer display name
wkidIntegerEPSG code (e.g. 4490 for CGCS2000)
geometryTypeGeometryTypePOINT, POLYGON, LINESTRING, etc.
toleranceDoubleGeometric tolerance
fieldsList<OguField>Field definitions
featuresList<OguFeature>Feature collection
metadataOguLayerMetadataExtended metadata

Methods: fromJSON(String), toJSON(), validate(), filter(OguFeatureFilter), getFeatureCount(), getFieldCount()

OguFeature

PropertyTypeDescription
idStringFeature identifier
geometryStringGeometry in WKT format
attributesList<OguFieldValue>Attribute values
coordinatesList<OguCoordinate>Coordinate points (TXT format)
rawValuesList<String>Raw values (TXT format)

Methods: getAttribute(String fieldName), getValue(String fieldName), setValue(String fieldName, Object value)

OguField

PropertyTypeDescription
nameStringField name
aliasStringDisplay name
descriptionStringDescription
dataTypeFieldDataTypeINTEGER, DOUBLE, STRING, DATE, etc.
lengthIntegerMax length (for STRING)
nullableBooleanNullable flag
defaultValueObjectDefault value

Constructors: OguField(name, alias, dataType), OguField(name, alias, description, dataType)

OguFieldValue

PropertyTypeDescription
fieldOguFieldField definition
valueObjectRaw value

Methods: getFieldName(), getStringValue(), getIntValue(), getDoubleValue()

OguCoordinate

PropertyTypeDescription
xDoubleX coordinate (longitude)
yDoubleY coordinate (latitude)
zDoubleZ coordinate (elevation, optional)
pointNumberStringPoint identifier
ringNumberIntegerRing/loop number

Constructors: OguCoordinate(x, y), OguCoordinate(x, y, z)

DbConnBaseModel(PostGIS 连接)

PropertyTypeDescription
dbTypeStringDatabase type
hostStringHost address
portStringPort number
schemaStringSchema name
databaseStringDatabase name
userStringUsername
passwdStringPassword

枚举速查

GeometryType

POINT, MULTIPOINT, LINESTRING, LINEARRING, MULTILINESTRING, POLYGON, MULTIPOLYGON, GEOMETRYCOLLECTION

Lookup methods: valueOfByTypeName(String), valueOfByTypeCode(int), valueOfByTypeClass(Class<?>), valueOfByWkbGeometryType(int)

FieldDataType

INTEGER, DOUBLE, STRING, BINARY, DATE, TIME, DATETIME, LONG

Lookup methods: fieldDataTypeByGdalCode(int), fieldDataTypeByTypeClass(Class<?>)

DataFormatType

WKT, GEOJSON, ESRIJSON, SHP, TXT, FILEGDB, POSTGIS, ARCSDE

Properties per value: desc (description), gdalDriverName (GDAL driver name)

GisEngineType

GEOTOOLS, GDAL, AUTO


异常层次

text
Exception
└── OguException                      # Base checked exception
    ├── DataSourceException           # Data source connection/access failure
    ├── EngineNotSupportedException   # Engine doesn't support the operation/format
    ├── FormatParseException          # Data format parsing failure
    └── TopologyException             # Geometry topology error

RuntimeException
└── LayerValidationException          # Layer data validation failure (unchecked)

架构与设计模式

  • Factory Pattern: GisEngineFactory creates engine instances; use GisEngineType.AUTO for automatic selection (prefers GDAL if available)
  • Strategy Pattern: LayerReader / LayerWriter interfaces define pluggable format-specific I/O strategies
  • Adapter Pattern: GisEngine provides a unified API over GeoTools and GDAL
  • Functional Interface: OguFeatureFilter enables lambda-based feature filtering
  • Geometry is WKT: Features store geometry as WKT strings in OguFeature.geometry; use GeometryUtil for conversion/operations

常见问题

问题解决
mvn install 依赖解析失败配置 osgeo 仓库(GeoTools 依赖不在 Maven Central);确认 Maven 3.8+ 与 JDK 17+
找不到 com.znlgis.ogu4j:ogu4j 依赖该库尚未发布到 Maven Central,先在本仓库执行 mvn install 安装到本地仓库
运行时报 GDAL 相关 UnsatisfiedLinkError本地缺少与 org.gdal:gdal 3.13.0 匹配的原生 GDAL;安装 GDAL 3.13.x,或改用 GisEngineType.GEOTOOLS
FileGDB 读写失败FileGDB 仅 GDAL 引擎支持:安装原生 GDAL 并使用 GisEngineType.GDAL 或 AUTO
Shapefile 字段名被截断DBF 规范限制 10 字符,使用 ShpUtil.formatFieldName() 自动截断
PostGIS 连接失败检查连接串格式(PG: host=... port=... dbname=... user=... password=... active_schema=...)与 schema 名称

AI 编码约定

  1. Always use OguLayerUtil as the primary entry point for reading/writing GIS data. It handles engine selection and format routing.

  2. Geometry in features is stored as WKT strings. Convert to JTS Geometry objects via GeometryUtil.wkt2Geometry() when you need spatial operations.

  3. Engine selection:

    • GisEngineType.AUTO — library auto-selects (prefers GDAL if available)
    • GisEngineType.GEOTOOLS — pure Java, always available, no native dependencies
    • GisEngineType.GDAL — requires native GDAL library installed; needed for FileGDB format
  4. CGCS2000 coordinate system (EPSG:4490) is the default/primary CRS. Projected CRS range: EPSG 4502-4554 (3-degree zones). Use CrsUtil for transformation.

  5. PostGIS connection strings follow the format: "PG: host=<host> port=<port> dbname=<db> user=<user> password=<pwd> active_schema=<schema>"

  6. Resource management:

    • DataStore objects (ShapefileDataStore, JDBCDataStore) must be disposed in finally blocks
    • OGR DataSource objects must be closed via OgrUtil.closeDataSource()
  7. Shapefile field names are limited to 10 characters. Use ShpUtil.formatFieldName() to auto-truncate.

  8. OguLayer can be serialized to/from JSON using layer.toJSON() and OguLayer.fromJSON(json) (backed by FastJSON2).

  9. Attribute filtering uses CQL expression syntax (e.g., "population > 1000000 AND name LIKE '%京%'").

  10. Spatial filtering accepts WKT geometry strings (e.g., "POLYGON((115 39, 117 39, 117 41, 115 41, 115 39))").

  11. Two geometry operation styles:

    • JTS-based: Pass Geometry objects, get Geometry back (e.g., GeometryUtil.buffer(geom, dist))
    • WKT-based (suffix Wkt): Pass WKT strings and WKID, get WKT back (e.g., GeometryUtil.bufferWkt(wkt, wkid, dist))
  12. Build with Maven: mvn compile — requires the OSGeo repository for GeoTools dependencies:

    xml
    <repository>
        <id>osgeo</id>
        <url>https://repo.osgeo.org/repository/release/</url>
    </repository>

典型工作流

以「Shapefile → 面积筛选 → 缓冲 → 投影 → GeoJSON」为例:输入 /data/parcels.shp(EPSG:4326),输出 /data/output.geojson(EPSG:4528)。

java
import com.znlgis.ogu4j.datasource.OguLayerUtil;
import com.znlgis.ogu4j.engine.enums.*;
import com.znlgis.ogu4j.engine.model.layer.*;
import com.znlgis.ogu4j.engine.util.CrsUtil;
import com.znlgis.ogu4j.geometry.GeometryUtil;
import org.locationtech.jts.geom.Geometry;

// Step 1: Read a Shapefile
OguLayer layer = OguLayerUtil.readLayer(
    DataFormatType.SHP, "/data/parcels.shp",
    null, null, null, GisEngineType.AUTO
);

// Step 2: Filter features by area > 10,000 square units
List<OguFeature> largeParcels = layer.filter(f -> {
    Geometry geom = GeometryUtil.wkt2Geometry(f.getGeometry());
    return GeometryUtil.area(geom) > 10000;
});

// Step 3: Buffer each geometry
for (OguFeature f : largeParcels) {
    Geometry geom = GeometryUtil.wkt2Geometry(f.getGeometry());
    Geometry buffered = GeometryUtil.buffer(geom, 50.0);
    f.setGeometry(GeometryUtil.geometry2Wkt(buffered));
}

// Step 4: Reproject to projected CRS
OguLayer projected = CrsUtil.reproject(layer, 4528);

// Step 5: Export to GeoJSON
OguLayerUtil.writeLayer(
    DataFormatType.GEOJSON, projected,
    "/data/output.geojson", null, null, GisEngineType.AUTO
);

// Step 6: 回读验证——要素数与 CRS 必须与预期一致,否则说明引擎或投影没生效
OguLayer check = OguLayerUtil.readLayer(
    DataFormatType.GEOJSON, "/data/output.geojson",
    null, null, null, GisEngineType.AUTO
);
System.out.println(check.getWkid() + " / " + check.getFeatureCount());

验收:mvn -q -DskipTests package 只说明能编译;实际运行上面的 main,打印的 WKID 应为 4528、要素数等于筛选后数量,output.geojson 用 ogrinfo -so 复查一遍。


AI 使用建议

  • 本技能的组织:主文件给高频用法,完整参数表与高级示例在 reference/common-tasks.md,需要时再展开;示例工程与生成的数据写到工作目录,不要改动技能目录本身。
  • 执行环境:先 java -version 与 mvn -version(需 JDK 17+、Maven 3.8+),Windows 用 PowerShell;mvn -v 里显示的 JDK 才是 Maven 实际使用的,与 shell 的 java 不一致时改 JAVA_HOME 再重试。
  • 源码安装(本库未发布到 Central):git clone https://github.com/znlgis/opengis-utils-for-java.git 后 mvn install -DskipTests,产物落在 ~/.m2/repository/com/znlgis/ogu4j/ogu4j/1.0.0/;用 mvn dependency:tree -Dincludes=com.znlgis.ogu4j 确认坐标可解析。不要在 pom.xml 里直接写 ogu4j:1.0.0 后指望从 Central 下载。
  • 仓库与网络:GeoTools 依赖不在 Central,pom.xml 必须带 https://repo.osgeo.org/repository/release/,否则 Could not resolve dependencies for org.geotools:*;离线或私服缺包时如实报告依赖不可下载,不要自行换版本或加未知仓库。
  • 原生 GDAL 匹配:GDAL 引擎绑定 org.gdal:gdal 3.13.0,本机需装 GDAL 3.13.x 且 java.library.path 能找到 gdal_jni(Windows 上 java -XshowSettings:properties -version 2>&1 | Select-String library.path);报 UnsatisfiedLinkError: no gdal_jni in java.library.path 说明原生库缺失或版本不符,此时改用 GisEngineType.GEOTOOLS。
  • 验证产物:写最小 main 读一个 Shapefile/GeoJSON → OguLayerUtil.readLayer(DataFormatType.SHP, path, null, null, null, GisEngineType.AUTO),打印 layer.getWkid()、layer.getFeatureCount(),再 writeLayer 成 GeoJSON 并重新读回比对要素数与 CRS;mvn -q -DskipTests package 只说明能编译。
  • 常见误操:AUTO 在本机有原生 GDAL 时会优先走 GDAL,想复现纯 Java 结果必须显式传 GisEngineType.GEOTOOLS;OguFeature.geometry 是 WKT 字符串,做运算前先 GeometryUtil.wkt2Geometry();DataStore 与 OGR DataSource 要在 finally 里释放,否则文件被占用后 writeLayer 覆盖失败。
  • 安全与权限:PostGIS 连接串(PG: host=... password=...)里的密码不要回显到输出;mvn install 会写 ~/.m2、示例代码会写 /data 等绝对路径,覆盖已有数据前先确认路径并征得用户同意。

相关技能

参考资源

附带文件

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

常见问题

Opengis Utils For Java AI 技能有什么作用?

Use when needing common GIS utilities in Java — OguLayerUtil layer read/write, GeometryUtil 60+ ops, CrsUtil CGCS2000 (EPSG:4490, 4502-4554), Shapefile/GeoJSON/FileGDB/PostGIS/land TXT I/O, topology validation; also for GDAL UnsatisfiedLinkError on gdal_jni, missing osgeo repo on GeoTools, or resolving com.znlgis.ogu4j:ogu4j:1.0.0 that is not on Maven Central. OGU4J.

为什么在 TypingMind 中使用 Opengis Utils For Java?

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

如何在 TypingMind 中安装 Opengis Utils For Java?

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

哪些 AI 模型可以使用 Opengis Utils For Java?

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

Opengis Utils For Java 可以搭配多少个 AI 模型使用?

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

Opengis Utils For Java AI 技能免费吗?

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

什么是 AI 技能?

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

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

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

查看全部

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

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