Lets-Plot for Kotlin 4.7.3 Help

Geospatial Charts

GeoTools is an open source Java GIS Toolkit.

Lets-Plot supports visualization of SimpleFeature objects organized in SimpleFeatureCollection, as well as individual Geometry (org.locationtech.jts.geom) and ReferencedEnvelope (org.geotools.geometry.jts) objects.

Lets-Plot API includes the SpatialDataset class serving as a bridge between external spatial data-types and Lets-Plot geometry layers.

A set of Kotlin extension methods with the signature toSpatialDataset(decimals: Int = 10): SpatialDataset is provided to facilitate converting GeoTools objects to an instance of the SpatialDataset class.

import org.jetbrains.letsPlot.spatial.SpatialDataset import org.jetbrains.letsPlot.toolkit.geotools.toSpatialDataset val data: SpatialDataset = featureCollection.toSpatialDataset()

The instance of SpatialDataset then can be passed to a plot geometry layer via the map or data parameters.

letsPlot() + geomPolygon(map = data, fill = "white", color = "gray")

The Lets-Plot library recognizes the following three 2D-geometry types:

  • Points

  • Lines

  • Polygons

These shapes can be plotted using various geometry layers that depend on the type of the shape:

All coordinates must be in decimal degree units, in "WGS 84" coordinates.

Creating Maps in JVM-Based Applications

For general information on using the Lets-Plot library in JVM-based application, see: USAGE_BATIK_JFX_JS.md

Maven Artifacts

In addition to the Maven artifacts that are required for regular plots, the artifact lets-plot-kotlin-geotools must be included to make the toSpatialDataset() method available.

You can include it into a Gradle project.

implementation 'org.jetbrains.lets-plot-kotlin:lets-plot-kotlin-geotools:4.7.3'

The gt-geojson artifact from GeoTools must be also included.

dependencies { ... implementation "org.jetbrains.lets-plot-kotlin:lets-plot-kotlin-geotools:4.7.3" implementation "org.geotools:gt-geojson:[30,)" ... }

The lets-plot-kotlin-api artifact was compiled with GeoTools v30.1. However, it doesn't declare any run-time dependency, so you are free to use other versions of the GeoTools toolkit.

JVM-Based Examples

The 'geotools-batik' subproject contains a set runnable examples that use Apache Batik SVG Toolkit for rendering.

Creating Maps in Notebooks

Lets-Plot can visualize maps in Kotlin Notebook, Datalore or Jupyter with Kotlin Kernel.

You can include all necessary dependencies into your notebook using the following "line magics":

%use lets-plot %use lets-plot-gt

By default, the lets-plot-gt magic installs the latest version of GeoTools artifacts - it uses "[30,)" version specification.

Thus, when declaring additional GeoTools dependencies in your notebook, you can do it as follows:

@file:DependsOn("org.geotools:gt-shapefile:[30,)") @file:DependsOn("org.geotools:gt-cql:[30,)")

If you have to use any different then the latest version of GeoTools, use the gt parameter in the lets-plot-gt magic to avoid possible compatibility issues.

%use lets-plot %use lets-plot-gt(gt=22.5)
@file:DependsOn("org.geotools:gt-shapefile:22.5") @file:DependsOn("org.geotools:gt-cql:22.5")

Example Notebooks

Last modified: 04 July 2024