Skip to content

Latest commit

 

History

History
143 lines (102 loc) · 5.31 KB

geotools.md

File metadata and controls

143 lines (102 loc) · 5.31 KB

Warning:

This documentation page is outdated.

For up-to-date information, see the Lets-Plot for Kotlin documentation website.

GeoTools Support


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 (jetbrains.letsPlot.spatial) 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:

  • Points : geomPoint, geomText
  • Lines : geomPath
  • Polygons : geomPolygon, geomMap. geomRect when used with Polygon shapes displays corresponding bounding boxes.

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_SWING_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'

Download

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.

Note: Since v4.6.0 Lets-Plot is only compatible with GeoTools v30 and later.

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 any notebook application that supports the Kotlin Jupyter Kernel.

At this moment, the applications that support Kotlin kernel are Jupyther itself and JetBrains Datalore.

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 "[23,)" version specification.

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

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

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

Couldn't load naturalearth_world.png