https://github.com/data2viz/geojson-kotlin
Multiplatform geojson serialization for kotlin
https://github.com/data2viz/geojson-kotlin
Last synced: 11 months ago
JSON representation
Multiplatform geojson serialization for kotlin
- Host: GitHub
- URL: https://github.com/data2viz/geojson-kotlin
- Owner: data2viz
- Created: 2018-02-20T14:11:36.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2023-02-17T23:40:27.000Z (over 3 years ago)
- Last Synced: 2025-04-11T03:07:32.222Z (about 1 year ago)
- Language: Kotlin
- Size: 1.64 MB
- Stars: 21
- Watchers: 3
- Forks: 5
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: license/LICENSE.txt
Awesome Lists containing this project
README
GeoJson Kotlin
=========================
[](https://travis-ci.org/data2viz/geojson-kotlin)
[](http://www.apache.org/licenses/LICENSE-2.0)
This project goal is to provide [GeoJson](https://tools.ietf.org/html/rfc7946) deserialization for kotlin multiplatform (JVM, JS).
The specific format of GeoJson files does not allow the use of kotlinx.serialization. JS and
JVM implementations are completely distinct but they share the same base objects and interfaces.
JVM implementation is based on the project [GeoJson-Jackson](https://github.com/opendatalab-de/geojson-jackson).
## Using in your projects
The library is published to data2viz space repository.
### Gradle
- Add the data2viz maven repository:
```kotlin
repositories {
maven { url = uri("https://maven.pkg.jetbrains.space/data2viz/p/maven/public") }
}
```
The project is deployed using Gradle metadata. You can use the dependency
on Gradle Metadata. Depending on your platform (JS or JVM) the correct
artifact will be imported.
```groovy
compile 'io.data2viz.geojson:core:0.6.6'
```
The JS version is available in [both modes](https://kotlinlang.org/docs/reference/js-ir-compiler.html), `Legacy` and `IR`.
You can then use the String extension toGeoJsonObject to transform any String into a GeoJsonObject:
```kotlin
val featureCollection = json.toGeoJsonObject() as FeatureCollection
```
If you deserialize a FeatureCollection that have properties (main use case) you
need to pass a function that transform the properties in a specific domain object.
```kotlin
class CountryProperties(val name: String, val id: Int)
val countries = countriesGeoJson.toFeatures {
CountryProperties(stringProperty("name"), intProperty("id"))
}
```
You then retrieve a list of `Pair`