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.

Installation

commonMain {
    dependencies {
        implementation("org.maplibre.spatialk:turf:0.4.0")
    }
}
dependencies {
    implementation("org.maplibre.spatialk:turf-jvm:0.4.0")
}

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();

Turf Functions

See the list of turf functions that have been ported.