Title: | Plot Raster Images Interactively on a Plain HTML Canvas |
---|---|
Description: | Provides methods for plotting potentially large (raster) images interactively on a plain HTML canvas. In contrast to package 'mapview' data are plotted without background map, but data can be projected to any spatial coordinate reference system. Supports plotting of classes 'RasterLayer', 'RasterStack', 'RasterBrick' (from package 'raster') as well as 'png' files located on disk. Interactivity includes zooming, panning, and mouse location information. In case of multi-layer 'RasterStacks' or 'RasterBricks', RGB image plots are created (similar to 'raster::plotRGB' - but interactive). |
Authors: | Tim Appelhans [cre, aut], Stefan Woellauer [aut] |
Maintainer: | Tim Appelhans <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2.1 |
Built: | 2024-11-05 04:43:11 UTC |
Source: | https://github.com/r-spatial/plainview |
Plot Raster Images Interactively on a Plain HTML Canvas
Provides methods for plotting potentially large (raster) images interactively on a plain HTML canvas. Supports plotting of RasterLayer, RasterStack, RasterBrick (from package raster) as well as png files located on disk. Interactivity includes zooming, panning, and mouse location information. In case of multi-layer RasterStacks or RasterBricks, RBG image plots are created (similar to raster::plotRGB - but interactive).
Tim Appelhans, Stephan Woellauer Maintainer: Tim Appelhans [email protected]
this function produces an interactive view of the specified raster object(s) on a plain grey background but for any CRS.
## S4 method for signature 'RasterLayer' plainView( x, maxpixels = 1e+08, col.regions = viridisLite::inferno, at, na.color = "#BEBEBE", legend = TRUE, verbose = FALSE, layer.name = deparse(substitute(x, env = parent.frame())), gdal = TRUE, ... ) ## S4 method for signature 'RasterStackBrick' plainView( x, r = 3, g = 2, b = 1, na.color = "#BEBEBE", maxpixels = 1e+08, layer.name = deparse(substitute(x, env = parent.frame())), ... ) ## S4 method for signature 'SpatialPixelsDataFrame' plainView(x, zcol = 1, ...) ## S4 method for signature 'ANY' plainview(...)
## S4 method for signature 'RasterLayer' plainView( x, maxpixels = 1e+08, col.regions = viridisLite::inferno, at, na.color = "#BEBEBE", legend = TRUE, verbose = FALSE, layer.name = deparse(substitute(x, env = parent.frame())), gdal = TRUE, ... ) ## S4 method for signature 'RasterStackBrick' plainView( x, r = 3, g = 2, b = 1, na.color = "#BEBEBE", maxpixels = 1e+08, layer.name = deparse(substitute(x, env = parent.frame())), ... ) ## S4 method for signature 'SpatialPixelsDataFrame' plainView(x, zcol = 1, ...) ## S4 method for signature 'ANY' plainview(...)
x |
a |
maxpixels |
integer > 0. Maximum number of cells to use for the plot.
If maxpixels < |
col.regions |
color (palette).See |
at |
the breakpoints used for the visualisation. See
|
na.color |
color for missing values. |
legend |
either logical or a list specifying any of the components
decribed in the |
verbose |
should some details be printed during the process |
layer.name |
the name of the layer to be shown on the map |
gdal |
logical. If TRUE (default) gdal_translate is used to create the png file for display when possible. See details for further information. |
... |
arguments passed on to respective methods |
r |
integer. Index of the Red channel, between 1 and nlayers(x) |
g |
integer. Index of the Green channel, between 1 and nlayers(x) |
b |
integer. Index of the Blue channel, between 1 and nlayers(x) |
zcol |
attribute name or column number in attribute table of the column to be rendered |
If the raster object is not in memory
(i.e. if raster::inMemory
is FLASE
)
and argument gdal
is set to TRUE (default) gdal_translate
is used to translate the rsater object to a png file to be rendered in
the viewer/browser. This is fast for large rasters. In this case, argument
maxpixels
is not used, instead the image is rendered in original resolution.
However, this means that RasterLayers will be shown in greyscale.
If you want to set a color palette manually, use gdal = FALSE
and
(optionally provide) col.regions
.
For plainView there are a few keyboard shortcuts defined:
plus/minus - zoom in/out
space - toggle antialiasing
esc - zoom to layer extent
enter - set zoom to 1
ctrl - increase panning speed by 10
plainView(SpatialPixelsDataFrame)
: SpatialPixelsDataFrame
plainview(ANY)
: alias for ease of typing
Stephan Woellauer
Tim Appelhans
if (interactive()) { # RasterLayer plainView(poppendorf[[4]]) # RasterStack plainview(poppendorf, r = 4, g = 3, b = 2) # true color plainview(poppendorf, r = 5, g = 4, b = 3) # false color }
if (interactive()) { # RasterLayer plainView(poppendorf[[4]]) # RasterStack plainview(poppendorf, r = 4, g = 3, b = 2) # true color plainview(poppendorf, r = 5, g = 4, b = 3) # false color }
Widget output/render function for use in Shiny
plainViewOutput(outputId, width = "100%", height = "400px") renderPlainView(expr, env = parent.frame(), quoted = FALSE)
plainViewOutput(outputId, width = "100%", height = "400px") renderPlainView(expr, env = parent.frame(), quoted = FALSE)
outputId |
Output variable to read from |
width , height
|
the width and height of the map
(see |
expr |
An expression that generates an HTML widget |
env |
The environment in which to evaluate expr |
quoted |
Is expr a quoted expression (with quote())? This is useful if you want to save an expression in a variable |
if (interactive()) { library(shiny) plt = plainView(poppendorf[[4]]) ui = fluidPage( plainViewOutput("plot") ) server = function(input, output, session) { output$plot <- renderPlainView(plt) } shinyApp(ui, server) }
if (interactive()) { library(shiny) plt = plainView(poppendorf[[4]]) ui = fluidPage( plainViewOutput("plot") ) server = function(input, output, session) { output$plot <- renderPlainView(plt) } shinyApp(ui, server) }
Landsat 8 detail of Franconian Switzerland centered on Poppendorf
"RasterBrick-class"
with 5 bands (bands 1 to 5).
Use of this data requires your agreement to the USGS regulations on using Landsat data.
https://earthexplorer.usgs.gov