Turf
Turf.js is a spatial analysis library for JavaScript applications. The turf
module is a Kotlin port with support for Kotlin Multiplatform and Java projects.
This module uses the classes from the geojson module as GeoJSON inputs to
turf functions.
Documentation for ported functions can be found in the API docs, while details on each function are available on the Turf.js site.
Installation
Section titled “Installation”commonMain { dependencies { implementation("org.maplibre.spatialk:turf:0.8.0") }}dependencies { implementation("org.maplibre.spatialk:turf-jvm:0.8.0")}Example
Section titled “Example”Turf functions are available as top-level functions in Kotlin and as static methods in Java.
val point = Position(-75.0, 45.0)val (longitude, latitude) = point.offset(100.kilometers, Bearing.North)Position origin = new Position(-75.0, 45.0);Position dest = offset(origin, 100, Kilometers, 0);dest.getLongitude();dest.getLatitude();Ported Functions
Section titled “Ported Functions”Measurement
Section titled “Measurement”-
along -
area -
bbox -
bboxPolygon -
bearing -
center -
centerOfMass -
centroid -
destination -
distance -
envelope -
greatCircle -
length -
midpoint -
pointOnFeature -
polygonTangents -
pointToLineDistance -
rhumbBearing -
rhumbDestination -
rhumbDistance -
square
Coordinate Mutation
Section titled “Coordinate Mutation”-
cleanCoords -
flip -
rewind -
round -
truncate
Transformation
Section titled “Transformation”-
bboxClip -
bezierSpline -
buffer -
circle -
clone -
concave -
convex -
difference -
dissolve -
intersect -
lineOffset -
simplify -
tessellate -
transformRotate -
transformTranslate -
transformScale -
union -
voronoi
Feature Conversion
Section titled “Feature Conversion”Geometry-preserving conversions keep bbox and foreignMembers. combine and explode rebuild
new geometries from coordinates and drop both.
-
combine -
explode -
flatten -
lineToPolygon -
polygonize -
polygonToLine
Miscellaneous
Section titled “Miscellaneous”-
kinks -
lineArc -
lineChunk -
lineIntersectPartially implemented. -
lineOverlap -
lineSegment -
lineSlice -
lineSliceAlong -
lineSplit -
mask -
nearestPointOnLine -
sector -
shortestPath -
unkinkPolygon
Helper
Section titled “Helper”Use the GeoJson DSL instead.
Random
Section titled “Random”-
randomPosition -
randomPoint -
randomLineString -
randomPolygon
-
sample
Interpolation
Section titled “Interpolation”-
interpolate -
isobands -
isolines -
planepoint -
tin
-
hexGrid -
pointGrid -
squareGrid -
triangleGrid
Classification
Section titled “Classification”Aggregation
Section titled “Aggregation”-
collect -
clustersDbscan -
clustersKmeans
Many GeoJson objects implement Collection, enabling standard Kotlin collection operations to
replace Turf meta functions.
Assertions
Section titled “Assertions”-
collectionOf -
containsNumber -
geojsonType -
featureOf
Booleans
Section titled “Booleans”-
booleanClockwise -
booleanContains -
booleanCrosses -
booleanDisjoint -
booleanEqual -
booleanOverlap -
booleanParallel -
booleanPointInPolygon -
booleanPointOnLine -
booleanWithin
Unit Conversion
Section titled “Unit Conversion”For converting between units of length, area, and angle, see the Units module.
-
toMercator -
toWgs84