view() of a list draws each element as one or more layers of a single
scene, in one view CRS, in list order: the first element at the bottom.
view_add() adds a layer to a view already made, on top, and writes a
new page, or, for a served view (see Transport in view()), serves the
new scene on the same server, at the same URL: a page open on it reloads
itself with the new scene and keeps its camera, the selection is cleared,
and the view given to view_add() is replaced (the selection functions,
selection(), are errors on it; use the view returned). view_add() on a
view that was already replaced still serves its scene plus x on the
same server, as a new scene (a new serial, and the open page reloads),
which replaces the newer one. An embedded view whose
local raster tiles pass the threshold with the new layer becomes served
(its earlier page stays on disk). view(a) |> view_add(b) gives the same scene as
view(list(a = a, b = b)) when the two have the same view CRS, that is
when view_crs(a) equals view_crs(list(a, b)), as it does whenever a
is projected, or a and b are both lon/lat south of 40S (or both north
of 60N). Otherwise they differ: view_add() keeps a's view CRS, while
the list's CRS is chosen from every element (below). Pass crs = to
either form to fix it.
Arguments
- x
For
view(), a list of spatial objects. Forview_add(), one spatial object (or a list of them) to add.- ...
For
view()of a list, nothing (per-layer arguments go toview_add()). Forview_add(), the argumentsview(), view-terra, view-matrix or view-stars take forx's class, such asfillorzcolforsfdata,geometryfor a stream,palettefor aSpatRasteror a 'stars' object, orextentandcrsfor a matrix.- crs
The view CRS, as for
view().NULLusesview_crs()of the list.- name
The page title. For a list, defaults to the layer labels joined by commas. For
view_add(), the new layer's name, which defaults to the expression passed asx; the page title becomes the view's name and this one, joined by a comma.- file
Path of the HTML file to write. Defaults to a new file in the session's temporary directory.
view_add()leavesv's page as it is. Not used by a served view (with a warning).- theme
As for
view().view_add()defaults tov's theme.- transport
As for
view(). Forview_add(), how the new layers are carried: on a served view,"embed"embeds a new local COG's tiles (the server delivers them as blobs) and"auto"or"serve"serve its file; the view stays served either way.- v
A view from
view()orview_add().
Value
A view, as for view().
Details
Elements may be any vector input view() takes (geometry 'wk' can
handle, a data frame with such a column, sf included, an Arrow stream
or table, an OGRFeatureSet), 'terra' SpatRaster or SpatVector
objects, 'stars' objects and proxies (see view-stars), and strings
(WKT text, or the path, URL or data source name of a raster or vector
source: see Strings in view()), in any mix of CRSs.
A matrix or array is not one, since it has no extent or CRS of its own:
add it with view_add(v, m, extent = , crs = ), where crs is the
grid's CRS, not the view's (see view-matrix).
Each is drawn as view(), view-terra or view-stars draws it on its
own, with its default style, and reprojected to the view CRS: vectors by 'PROJ'
(lon/lat edges densified first), rasters by aobcore::cog_plan()'s
meshes. A stream is read once, before the view CRS is chosen; one whose
geometry has no CRS is taken to be in crs, which view() of the list
must then be given, or in the view's CRS for view_add() (see Arrow
streams in view()).
View CRS. crs when given; otherwise view_crs() of the whole list:
the CRS of the first element with a projected CRS, or, when every element
is in lon/lat, the lon/lat rule applied once to their combined latitude
range. view_add() keeps the view's CRS and reprojects x to it; it
warns when that puts projected vector data into a geographic view
(decision 0004 rules out that per-coordinate transform), and a crs
argument to it is an error.
Names. List names become layer labels and, made valid and unique,
layer ids. An unnamed element takes the expression that gave it in a
call such as view(list(coast, r)) (a string literal is named as
view() names it: its base name, or the WKT text), else x[[i]]. When
an id is taken, _2, _3, ... is appended.
Initial view. The union of the layers' extents in the view CRS,
clipped to the view's domain (aobcore::crs_domain(), carried as the
scene's view.bounds, allboa/design decision 0005). The scene's spec
version is the highest any of its layers or its view needs.
For a style of your own on one layer, such as colour by attribute
(zcol), start with view() of it or add it with view_add(), which
take each kind's arguments.
Examples
coast <- sf::st_read(system.file("extdata", "coastline_south_40s.geojson",
package = "aobcore"), quiet = TRUE)
stations <- sf::st_sfc(sf::st_point(c(110.53, -66.28)), sf::st_point(c(77.97, -68.58)),
crs = "OGC:CRS84")
v <- view(list(coast = coast, stations = stations))
vapply(v$scene$layers, function(l) l$id, "")
#> [1] "coast" "stations"
v2 <- view_add(view(coast), stations, fill = c(220, 60, 40, 255))
v2$scene$layers[[2]]$fill
#> [1] 220 60 40 255
sites <- sf::st_sf(base = c("Casey", "Davis"), geometry = stations)
v3 <- view_add(view(coast), sites, zcol = "base")
v3$scene$layers[[2]]$fill
#> $column
#> [1] "color"
#>
sst <- terra::rast(system.file("extdata", "polar_3031.tif", package = "aobcore"))
v3 <- view(list(sst = sst, coast = coast))
v3$scene$view$crs
#> [1] "EPSG:3031"