在 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/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值