目錄
- 1 說明
- Geometry 類
- 2 安裝
- 3 使用
- 以 buffer 為例
- 4 JTS 檔案
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/
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/423841.html
標籤:其他
