在 esmodule 环境下使用 jsts


1 说明

jsts 完全就是根据其老妈 jts 的 java 包结构移植的,除了部分分析功能需要额外注意外,基本上所有的子模块的根路径位于 jsts/org/locationtech/jts 模块下。

Geometry 类

Geometry 类符合 OGC 简单要素规范的设计。它有若干个子类,例如点线面等。

Geometry 在 JTS 上有非常多实用的空间分析函数:

buffer, buffer, buffer, compareTo, compareTo, contains, convexHull, copy, coveredBy, covers, crosses, difference, disjoint, distance, equals, equals, equalsExact, equalsNorm, equalsTopo, geometryChanged, getArea, getCentroid, getEnvelope, getEnvelopeInternal, getFactory, getGeometryN, getInteriorPoint, getLength, getNumGeometries, getPrecisionModel, getSRID, getUserData, hashCode, intersection, intersects, isRectangle, isValid, isWithinDistance, norm, overlaps, relate, relate, setSRID, setUserData, symDifference, toString, toText, touches, union, union, within

但是不见得所有的都在 JSTS 中有,见第 3 节的 buffer 举例。

turf 的分析函数在特定条件下是计算失败的(已验证),所以我才不得不求助于 JSTS

2 安装

pnpm add jsts && pnpm add @types/jsts --save-dev

# or
npm install jsts && npm install @types/jsts --save-dev
# or
yarn add jsts && yarn add @types/jsts --save-dev

@types/jsts 是类型提示库

3 使用

以 buffer 为例

import JSTSWKTReader from 'jsts/org/locationtech/jts/io/WKTReader'
import JSTSGeoJSONWriter from 'jsts/org/locationtech/jts/io/GeoJSONWriter'
import JSTSBufferOp from 'jsts/org/locationtech/jts/operation/buffer/BufferOp'

const wkt = `POINT (0 0)`
const bufferCenter = new JSTSWKTReader().read(wkt)
const bufferResult = JSTSBufferOp.bufferOp(
  bufferCenter,
  this.bufferRadius
) // instanceof Geometry

const bufferResultGeoJSON = new JSTSGeoJSONWriter().write(bufferResult)

4 JTS 文档

http://locationtech.github.io/jts/javadoc/

posted @   岭南灯火  阅读(355)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
· .NET 10 首个预览版发布,跨平台开发与性能全面提升
· 《HelloGitHub》第 107 期
· 全程使用 AI 从 0 到 1 写了个小工具
· 从文本到图像:SSE 如何助力 AI 内容实时呈现?(Typescript篇)
历史上的今天:
2017-02-14 ArcGIS API for JavaScript 4.2学习笔记[11] 官方第五章Popups(弹窗)概览与解释
点击右上角即可分享
微信分享提示