Spatial K - A set of Kotlin Multiplatform Libraries for working with geospatial data https://maplibre.org/spatial-k/
  • Kotlin 95.3%
  • Swift 2.9%
  • Java 1.4%
  • Shell 0.3%
Find a file
dependabot[bot] 0b8ec95bf0
build(deps): bump org.jetbrains.kotlinx:ktfmt from 0.65 to 0.65.1 (#479)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-12-01 12:22:14 -05:00
.github build(deps): bump jdx/mise-action from 5.2.10 to 5.3.0 (#476) 2026-12-01 12:21:56 -05:00
.vscode chore: format json, markdown, toml, and yaml with oxc (#443) 2026-10-24 21:06:26 -07:00
.zed chore: format json, markdown, toml, and yaml with oxc (#443) 2026-10-24 21:06:26 -07:00
benchmark chore: drop deprecated Kotlin JS compiler type and Gradle getting (#456) 2026-10-31 13:52:19 -07:00
buildSrc chore: drop deprecated Kotlin JS compiler type and Gradle getting (#456) 2026-10-31 13:52:19 -07:00
docs chore(deps): update tooling Dependabot does not cover (#472) 2026-11-28 10:00:14 -08:00
geohash chore: format json, markdown, toml, and yaml with oxc (#443) 2026-10-24 21:06:26 -07:00
geojson fix(geojson): stop Swift crash when creating GeoJSON objects (#449) 2026-10-26 13:13:44 -07:00
gpx chore: format json, markdown, toml, and yaml with oxc (#443) 2026-10-24 21:06:26 -07:00
gradle build(deps): bump org.jetbrains.kotlinx:ktfmt from 0.65 to 0.65.1 (#479) 2026-12-01 12:22:14 -05:00
kotlin-js-store Bump kotlin from 2.4.10 to 2.4.20 (#391) 2026-10-03 23:35:02 -07:00
mise-tasks/publish Add PMTiles Swift package artifacts (#338) 2026-06-06 16:08:14 -07:00
pmtiles build: update ktfmt to 0.65 under its new Maven coordinates (#430) 2026-10-17 19:54:59 -07:00
polyline-encoding chore(deps): update dprint plugins (#439) 2026-10-24 13:06:08 -07:00
testutil chore: drop deprecated Kotlin JS compiler type and Gradle getting (#456) 2026-10-31 13:52:19 -07:00
tools/units-generator build: run the toolchain on Java 25 LTS (#434) 2026-10-17 20:49:32 -07:00
turf chore: format json, markdown, toml, and yaml with oxc (#443) 2026-10-24 21:06:26 -07:00
units build: update ktfmt to 0.65 under its new Maven coordinates (#430) 2026-10-17 19:54:59 -07:00
.coderabbit.yml chore: format json, markdown, toml, and yaml with oxc (#443) 2026-10-24 21:06:26 -07:00
.gitattributes feat(units)!: expand unit catalogs and codegen their definitions (#395) 2026-10-03 22:40:55 -07:00
.gitignore Add PMTiles Swift package artifacts (#338) 2026-06-06 16:08:14 -07:00
AGENTS.md chore(deps): update mise tools (#427) 2026-10-17 18:03:28 -07:00
AI_POLICY.md docs: simplify contributor and PR guidance (#399) 2026-10-03 16:11:37 -07:00
BENCHMARK.md streamline toolchain: mise to install tools, hk to orchestrate linters, dprint to orchestrate formatters (#306) 2026-04-04 05:06:09 +02:00
build.gradle.kts feat(geohash): add Geohash cells and OsmShortlink (#383) 2026-08-29 20:40:16 -07:00
CLAUDE.md Link to MapLibre org AI policy (#317) 2026-04-22 20:54:47 -07:00
CODE-OF-CONDUCT.md Configure and run an auto formatter on all files (and enforce in CI) (#157) 2025-09-24 07:44:18 +00:00
CONTRIBUTING.md chore: format json, markdown, toml, and yaml with oxc (#443) 2026-10-24 21:06:26 -07:00
detekt.yml chore: format json, markdown, toml, and yaml with oxc (#443) 2026-10-24 21:06:26 -07:00
dprint.jsonc chore(deps): update tooling Dependabot does not cover (#472) 2026-11-28 10:00:14 -08:00
gradle.properties [codex] Simplify publishing workflow (#337) 2026-06-06 14:03:19 -07:00
gradlew Bump gradle-wrapper from 9.5.1 to 9.6.0 (#352) 2026-06-22 17:05:16 +02:00
gradlew.bat Bump gradle-wrapper from 9.7.1 to 9.8.0 (#393) 2026-09-27 22:02:21 -07:00
hk.pkl chore(deps): update tooling Dependabot does not cover (#472) 2026-11-28 10:00:14 -08:00
LICENSE update code of conduct etc 2025-09-22 17:14:13 +02:00
mise.lock chore(deps): update tooling Dependabot does not cover (#472) 2026-11-28 10:00:14 -08:00
mise.toml chore(deps): update tooling Dependabot does not cover (#472) 2026-11-28 10:00:14 -08:00
package.json chore: format json, markdown, toml, and yaml with oxc (#443) 2026-10-24 21:06:26 -07:00
pnpm-lock.yaml chore(deps): update tooling Dependabot does not cover (#472) 2026-11-28 10:00:14 -08:00
pnpm-workspace.yaml chore: format json, markdown, toml, and yaml with oxc (#443) 2026-10-24 21:06:26 -07:00
README.md chore(deps): update dprint plugins (#439) 2026-10-24 13:06:08 -07:00
SECURITY.md streamline toolchain: mise to install tools, hk to orchestrate linters, dprint to orchestrate formatters (#306) 2026-04-04 05:06:09 +02:00
settings.gradle.kts feat(units)!: expand unit catalogs and codegen their definitions (#395) 2026-10-03 22:40:55 -07:00

Spatial K

Maven Central Version Snapshot Version License Kotlin Version Documentation API Reference Slack

Introduction

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
  • GPX implementation
  • PMTiles v3 archive reader
  • Google Encoded Polyline Algorithm support
  • Geohash cells and OpenStreetMap shortlinks

Spatial K supports Kotlin Multiplatform and Java projects.

Getting Started

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")
    implementation("org.maplibre.spatialk:gpx:VERSION")
    implementation("org.maplibre.spatialk:pmtiles:VERSION")
    implementation("org.maplibre.spatialk:polyline-encoding:VERSION")
    implementation("org.maplibre.spatialk:geohash:VERSION")
}

GeoJSON

val sf = buildFeature {
    geometry = Point(longitude = -122.4, latitude = 37.8)
    properties = buildJsonObject {
        put("name", "San Francisco")
    }
}

val json: String = sf.toJson()

Turf

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)

Units

val distance = 5.kilometers
val inMeters = distance.inMeters // 5000.0
val formatted = distance.toString() // "5000 m"

GPX

val document =
    Document(
        metadata = Metadata(name = "My GPX File"),
        waypoints =
            listOf(
                Waypoint(latitude = 1.0, longitude = 2.0),
                Waypoint(latitude = 3.0, longitude = 4.0),
            ),
    )
val gpxString = Gpx.encodeToString(document)

PMTiles

// Inside a suspend function or coroutine scope:
PmTiles.open(source).use { archive ->
    val header = archive.header
    val tile = archive.readDecompressedTile(z = 0, x = 0, y = 0)
}

Polyline Encoding

val positions =
    listOf(
        Position(longitude = -120.2, latitude = 38.5),
        Position(longitude = -120.95, latitude = 40.7),
    )
val encoded = PolylineEncoding.encode(positions)
val decoded = PolylineEncoding.decode(encoded)

See the project site for more info.

Getting Involved

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.