All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jetbrains.letsPlot.toolkit.geotools.GeometryEx.kt Maven / Gradle / Ivy

Go to download

Lets-Plot Kotlin GeoTools Bridge. Requires GeoTools artifacts: - org.geotools:gt-main:[30,) - org.geotools:gt-geojson:[30,)

There is a newer version: 4.8.0
Show newest version
/*
 * Copyright (c) 2022. JetBrains s.r.o.
 * Use of this source code is governed by the MIT license that can be found in the LICENSE file.
 */

package org.jetbrains.letsPlot.toolkit.geotools

import org.geotools.geojson.geom.GeometryJSON
import org.jetbrains.letsPlot.spatial.SpatialDataset
import org.locationtech.jts.geom.Geometry

/**
 * Transforms Geometry to SpatialDataset with feature geometries encoded in GEOJSON format.
 *
 * @param decimals the number of decimals to use when encoding floating point numbers.
 */
fun Geometry.toSpatialDataset(decimals: Int = 10): SpatialDataset {
    require(this.isValid) { "Invalid geometry: ${this.geometryType}" }

    val geoJson = GeometryJSON(decimals).toString(this)
    return SpatialDataset.withGEOJSON(emptyMap(), listOf(geoJson))
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy