Skip to content

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.

commonMain {
dependencies {
implementation("org.maplibre.spatialk:turf:0.8.0")
}
}

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)
  • cleanCoords
  • flip
  • rewind
  • round
  • truncate
  • bboxClip
  • bezierSpline
  • buffer
  • circle
  • clone
  • concave
  • convex
  • difference
  • dissolve
  • intersect
  • lineOffset
  • simplify
  • tessellate
  • transformRotate
  • transformTranslate
  • transformScale
  • union
  • voronoi

Geometry-preserving conversions keep bbox and foreignMembers. combine and explode rebuild new geometries from coordinates and drop both.

Use the GeoJson DSL instead.

  • randomPosition
  • randomPoint
  • randomLineString
  • randomPolygon
  • sample
  • interpolate
  • isobands
  • isolines
  • planepoint
  • tin
  • collect
  • clustersDbscan
  • clustersKmeans

Many GeoJson objects implement Collection, enabling standard Kotlin collection operations to replace Turf meta functions.

  • collectionOf
  • containsNumber
  • geojsonType
  • featureOf
  • booleanClockwise
  • booleanContains
  • booleanCrosses
  • booleanDisjoint
  • booleanEqual
  • booleanOverlap
  • booleanParallel
  • booleanPointInPolygon
  • booleanPointOnLine
  • booleanWithin

For converting between units of length, area, and angle, see the Units module.

  • toMercator
  • toWgs84