
Set of libraries for working with geospatial data, including GeoJson implementation and a port of Turfjs, featuring a Kotlin DSL for building GeoJson objects.
Spatial K is a set of libraries for working with geospatial data in Kotlin.
It includes:
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")
implementation("org.maplibre.spatialk:gpx:VERSION")
implementation("org.maplibre.spatialk:pmtiles:VERSION")
implementation("org.maplibre.spatialk:polyline-encoding: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"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)// 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)
}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.
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.
Spatial K is a set of libraries for working with geospatial data in Kotlin.
It includes:
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")
implementation("org.maplibre.spatialk:gpx:VERSION")
implementation("org.maplibre.spatialk:pmtiles:VERSION")
implementation("org.maplibre.spatialk:polyline-encoding: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"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)// 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)
}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.
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.