1 explain
jsts It's all based on his mother jts Of java Transplantation of package structure , In addition to some analysis functions that require additional attention , Basically, the root path of all sub modules is located in jsts/org/locationtech/jts
Under module .
Geometry class
Geometry Class coincidence OGC Design of simple element specification . It has several subclasses , For example, point, line, surface, etc .
Geometry stay JTS There are many practical spatial analysis functions :
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
But not all of them are JSTS
There is , See the first 3 Chaste buffer give an example .
turf The analysis function of is computationally failed under certain conditions ( Verified ), That's why I have to turn to JSTS
2 install
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 Is a type prompt Library
3 Use
With buffer For example
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)