SpatialDataset Preview¶

You can preview a SpatialDataset, which stores geospatial data for Lets-Plot map layers, as a compact table.

In [1]:
%useLatestDescriptors
%use lets-plot
In [2]:
LetsPlot.getInfo()
Out[2]:
Lets-Plot Kotlin API v.4.15.0. Frontend: Notebook with dynamically loaded JS. Lets-Plot JS v.4.11.0.
Outputs: Web (HTML+JS), Kotlin Notebook (Swing), Static SVG (hidden)

Spatial Dataset Preview¶

Notebook previews show at most 5 rows; this sample has 7 landmarks.

In [3]:
val places = SpatialDataset.withGEOJSON(
    data = mapOf(
        "name" to listOf("Museum", "Garden", "Harbor", "Library", "Market", "Gallery", "Pier"),
        "kind" to listOf("culture", "park", "waterfront", "culture", "food", "culture", "waterfront"),
        "visitors" to listOf(120, 95, 80, 65, 140, 55, 110)
    ),
    geometry = listOf(
        "{\"type\":\"Point\",\"coordinates\":[-73.9857,40.7484]}",
        "{\"type\":\"Point\",\"coordinates\":[-73.9654,40.7829]}",
        "{\"type\":\"Point\",\"coordinates\":[-74.0122,40.7061]}",
        "{\"type\":\"Point\",\"coordinates\":[-73.9822,40.7532]}",
        "{\"type\":\"Point\",\"coordinates\":[-73.9969,40.7223]}",
        "{\"type\":\"Point\",\"coordinates\":[-74.0030,40.7506]}",
        "{\"type\":\"Point\",\"coordinates\":[-74.0108,40.7033]}"
    )
)

places
Out[3]:
namekindvisitorsgeometry
Museumculture120POINT (-73.9857 40.7484)
Gardenpark95POINT (-73.9654 40.7829)
Harborwaterfront80POINT (-74.0122 40.7061)
Libraryculture65POINT (-73.9822 40.7532)
Marketfood140POINT (-73.9969 40.7223)
Showing 5 of 7 rows
In [4]:
letsPlot() +
    geomPoint(map = places) {
        color = "kind"
        size = "visitors"
    } +
    geomText(map = places, nudgeX = 0.01, hjust = "left") {
        label = "name"
    } +
    scaleSize(range = 5 to 12) +
    labs(color = "place type", size = "visitors") +
    ggtitle("Landmarks from a SpatialDataset") +
    ggsize(650, 420) +
    themeVoid()
Out[4]:
Museum Garden Harbor Library Market Gallery Pier Landmarks from a SpatialDataset visitors 60 80 100 120 140 place type culture park waterfront food

Inspect a Real-World Dataset¶

A SpatialDataset can also wrap geospatial data loaded through GeoTools.

In [5]:
@file:Repository("https://repo.osgeo.org/repository/release/")
@file:DependsOn("org.geotools:gt-shapefile:33.2")
@file:DependsOn("org.geotools:gt-epsg-hsql:33.2")
In [6]:
%use lets-plot-gt
In [7]:
import org.geotools.data.shapefile.ShapefileDataStoreFactory
import java.net.URL

val shpUrl = "https://raw.githubusercontent.com/JetBrains/lets-plot-kotlin/master/docs/examples/shp/naturalearth_lowres/naturalearth_lowres.shp"
val countries = ShapefileDataStoreFactory()
    .createDataStore(URL(shpUrl))
    .featureSource.features
    .toSpatialDataset()
In [8]:
countries
Out[8]:
pop_estcontinentnameiso_a3gdp_md_estgeometry
920938OceaniaFijiFJI8374MULTIPOLYGON (((180 -16.0671, ...)), ...)
53950935AfricaTanzaniaTZA150600MULTIPOLYGON (((33.9037 -0.95, ...)))
603253AfricaW. SaharaESH906.5MULTIPOLYGON (((-8.6656 27.6564, ...)))
35623680North AmericaCanadaCAN1674000MULTIPOLYGON (((-122.84 49, ...)), ...)
326625791North AmericaUnited States of AmericaUSA18560000MULTIPOLYGON (((-122.84 49, ...)), ...)
Showing 5 of 177 rows

Geometry cells are shown as compact WKT-style previews; only the first 5 of its 177 rows are displayed.

In [9]:
letsPlot() +
    geomMap(map = countries) { fill = "continent" } +
    labs(fill = "continent") +
    ggtitle("Natural Earth countries") +
    ggsize(800, 450) +
    themeVoid()
Out[9]:
Natural Earth countries continent Oceania Africa North America Asia South America Europe Seven seas (open ocean) Antarctica