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…