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]:
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]:
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]:
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]:
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]: