Spatial K is a set of libraries for working with geospatial data in Kotlin.
It includes:
- GeoJSON implementation and DSL for building GeoJSON objects
- Port of Turf.js geospatial analysis functions in pure Kotlin
- Library for working with units of measure
Spatial K supports Kotlin Multiplatform and Java projects.
Add Spatial K to your project:
dependencies {
implementation("org.maplibre.spatialk:geojson:VERSION")
implementation("org.maplibre.spatialk:turf:VERSION")
implementation("org.maplibre.spatialk:units:VERSION")
}
val sf = buildFeature {
geometry = Point(longitude = -122.4, latitude = 37.8)
properties = buildJsonObject {
put("name", "San Francisco")
}
}
val json: String = sf.toJson()
val from = Position(longitude = -122.4, latitude = 37.8)
val to = Position(longitude = -74.0, latitude = 40.7)
val distance = distance(from, to)
val bearing = from.bearingTo(to)
val distance = 5.kilometers
val inMeters = distance.inMeters // 5000.0
val formatted = distance.toString() // "5000 m"
See the project site for more info.
Join the #maplibre Slack channel at OSMUS (get an invite at https://slack.openstreetmap.us/).
Read the CONTRIBUTING.md guide to get familiar with how we do things around here.