
jetbrains.letsPlot.toolkit.geotools.FeatureCollectionExt.kt Maven / Gradle / Ivy
/*
* Copyright (c) 2020. JetBrains s.r.o.
* Use of this source code is governed by the MIT license that can be found in the LICENSE file.
*/
package jetbrains.letsPlot.toolkit.geotools
import jetbrains.letsPlot.spatial.SpatialDataset
import org.geotools.data.simple.SimpleFeatureCollection
import org.geotools.geojson.geom.GeometryJSON
import org.locationtech.jts.geom.Geometry
import org.opengis.feature.type.GeometryDescriptor
/**
* Transforms SimpleFeatureCollection to SpatialDataset with feature geometries encoded in GEOJSON format.
*
* @param decimals the number of decimals to use when encoding floating point numbers.
*/
fun SimpleFeatureCollection.toSpatialDataset(decimals: Int = 10): SpatialDataset {
val geojson = GeometryJSON(decimals)
val (data, geometries) = getDataAndGeometries(this) {
geojson.toString(it)
}
return SpatialDataset.withGEOJSON(data, geometries)
}
private fun getDataAndGeometries(
featureCollection: SimpleFeatureCollection,
geometryToString: (Geometry) -> String
): Pair
© 2015 - 2025 Weber Informatics LLC | Privacy Policy