mapView

0th

Percentile

View spatial objects interactively

this function produces an interactive view of the specified spatial object(s) on top of the specified base maps.

Usage
# S4 method for RasterLayer
mapView(x, map = NULL,
  maxpixels = mapviewGetOption("mapview.maxpixels"),
  col.regions = mapviewGetOption("raster.palette")(256), at = NULL,
  na.color = mapviewGetOption("na.color"), use.layer.names = FALSE,
  values = NULL, map.types = mapviewGetOption("basemaps"),
  alpha.regions = 0.8, legend = mapviewGetOption("legend"),
  legend.opacity = 1, trim = TRUE, verbose = mapviewGetOption("verbose"),
  layer.name = NULL, homebutton = TRUE, native.crs = FALSE, ...)

# S4 method for RasterStackBrick mapView(x, map = NULL, maxpixels = mapviewGetOption("mapview.maxpixels"), col.regions = mapviewGetOption("raster.palette")(256), at = NULL, na.color = mapviewGetOption("na.color"), use.layer.names = TRUE, values = NULL, map.types = mapviewGetOption("basemaps"), legend = mapviewGetOption("legend"), legend.opacity = 1, trim = TRUE, verbose = mapviewGetOption("verbose"), homebutton = TRUE, ...)

# S4 method for Satellite mapView(x, map = NULL, maxpixels = mapviewGetOption("mapview.maxpixels"), col.regions = mapviewGetOption("raster.palette")(256), at = NULL, na.color = mapviewGetOption("na.color"), values = NULL, map.types = mapviewGetOption("basemaps"), legend = mapviewGetOption("legend"), legend.opacity = 1, trim = TRUE, verbose = mapviewGetOption("verbose"), homebutton = TRUE, ...)

# S4 method for sf mapView(x, map = NULL, zcol = NULL, burst = FALSE, color = mapviewGetOption("vector.palette"), col.regions = mapviewGetOption("vector.palette"), at = NULL, na.color = mapviewGetOption("na.color"), cex = 6, lwd = lineWidth(x), alpha = 0.9, alpha.regions = regionOpacity(x), na.alpha = regionOpacity(x), map.types = NULL, verbose = mapviewGetOption("verbose"), popup = popupTable(x), layer.name = NULL, label = makeLabels(x, zcol), legend = mapviewGetOption("legend"), legend.opacity = 1, homebutton = TRUE, native.crs = FALSE, highlight = mapviewHighlightOptions(x, alpha.regions, alpha, lwd), maxpoints = getMaxFeatures(x), ...)

# S4 method for sfc mapView(x, map = NULL, color = standardColor(x), col.regions = standardColRegions(x), at = NULL, na.color = mapviewGetOption("na.color"), cex = 6, lwd = lineWidth(x), alpha = 0.9, alpha.regions = regionOpacity(x), map.types = NULL, verbose = mapviewGetOption("verbose"), popup = NULL, layer.name = deparse(substitute(x, env = parent.frame(2))), label = makeLabels(x), legend = mapviewGetOption("legend"), legend.opacity = 1, homebutton = TRUE, native.crs = FALSE, highlight = mapviewHighlightOptions(x, alpha.regions, alpha, lwd), maxpoints = getMaxFeatures(x), ...)

# S4 method for numeric mapView(x, y, type = "p", grid = TRUE, label, ...)

# S4 method for data.frame mapView(x, xcol, ycol, grid = TRUE, aspect = 1, popup = popupTable(x), label, ...)

# S4 method for XY mapView(x, map = NULL, color = standardColor(x), col.regions = standardColRegions(x), at = NULL, na.color = mapviewGetOption("na.color"), cex = 6, lwd = lineWidth(x), alpha = 0.9, alpha.regions = regionOpacity(x), map.types = NULL, verbose = mapviewGetOption("verbose"), popup = NULL, layer.name = deparse(substitute(x, env = parent.frame(1))), label = makeLabels(x), legend = mapviewGetOption("legend"), legend.opacity = 1, homebutton = TRUE, native.crs = FALSE, highlight = mapviewHighlightOptions(x, alpha.regions, alpha, lwd), maxpoints = getMaxFeatures(x), ...)

# S4 method for XYZ mapView(x, layer.name = deparse(substitute(x, env = parent.frame(1))), ...)

# S4 method for XYM mapView(x, layer.name = deparse(substitute(x, env = parent.frame(1))), ...)

# S4 method for XYZM mapView(x, layer.name = deparse(substitute(x, env = parent.frame(1))), ...)

# S4 method for sfc_POINT mapView(x, ...)

# S4 method for sfc_MULTIPOINT mapView(x, ...)

# S4 method for sfc_LINESTRING mapView(x, ...)

# S4 method for sfc_MULTILINESTRING mapView(x, ...)

# S4 method for sfc_POLYGON mapView(x, ...)

# S4 method for sfc_MULTIPOLYGON mapView(x, ...)

# S4 method for sfc_GEOMETRY mapView(x, ...)

# S4 method for bbox mapView(x, layer.name = deparse(substitute(x, env = parent.frame(1))), alpha.regions = 0.2, ...)

# S4 method for missing mapView(map.types = mapviewGetOption("basemaps"), ...)

# S4 method for list mapView(x, map = NULL, zcol = NULL, burst = FALSE, color = mapviewGetOption("vector.palette"), col.regions = mapviewGetOption("vector.palette"), at = NULL, na.color = mapviewGetOption("na.color"), cex = 6, lwd = lapply(x, lineWidth), alpha = lapply(seq(x), function(i) 0.9), alpha.regions = lapply(seq(x), function(i) 0.6), map.types = mapviewGetOption("basemaps"), verbose = mapviewGetOption("verbose"), popup = lapply(seq(x), function(i) { popupTable(x[[i]]) }), layer.name = deparse(substitute(x, env = parent.frame())), label = lapply(seq(x), function(i) { makeLabels(x[[i]], zcol = zcol[[i]]) }), legend = mapviewGetOption("legend"), legend.opacity = 1, homebutton = TRUE, native.crs = FALSE, maxpoints = NULL, ...)

# S4 method for ANY mapview(...)

# S4 method for SpatialPixelsDataFrame mapView(x, zcol = NULL, na.color = mapviewGetOption("na.color"), legend = mapviewGetOption("legend"), ...)

# S4 method for SpatialGridDataFrame mapView(x, zcol = NULL, ...)

# S4 method for SpatialPointsDataFrame mapView(x, zcol = NULL, layer.name = NULL, ...)

# S4 method for SpatialPoints mapView(x, zcol = NULL, layer.name = NULL, ...)

# S4 method for SpatialPolygonsDataFrame mapView(x, zcol = NULL, layer.name = NULL, ...)

# S4 method for SpatialPolygons mapView(x, zcol = NULL, layer.name = NULL, ...)

# S4 method for SpatialLinesDataFrame mapView(x, zcol = NULL, layer.name = NULL, ...)

# S4 method for SpatialLines mapView(x, zcol = NULL, layer.name = NULL, ...)

Arguments
x

a Raster* or Spatial* or Satellite or sf object or a list of any combination of those. Furthermore, this can also be a data.frame or a numeric vector.

map

an optional existing map to be updated/added to

maxpixels

integer > 0. Maximum number of cells to use for the plot. If maxpixels < ncell(x), sampleRegular is used before plotting.

col.regions

color (palette) pixels. See levelplot for details.

at

the breakpoints used for the visualisation. See levelplot for details.

na.color

color for missing values

use.layer.names

should layer names of the Raster* object be used?

values

a vector of values for the visualisation of the layers. Per default these are calculated based on the supplied raster* object.

map.types

character spcifications for the base maps. see http://leaflet-extras.github.io/leaflet-providers/preview/ for available options.

alpha.regions

opacity of the fills of points, polygons or raster layer(s)

legend

should a legend be plotted

legend.opacity

opacity of the legend

trim

should the raster be trimmed in case there are NAs on the egdes

verbose

should some details be printed during the process

layer.name

the name of the layer to be shown on the map

homebutton

logical, whether to add a zoom-to-layer button to the map. Defaults to TRUE

native.crs

logical whether to reproject to web map coordinate reference system (web mercator - epsg:3857) or render using native CRS of the supplied data (can also be NA). Default is FALSE which will render in web mercator. If set to TRUE now background maps will be drawn (but rendering may be much quicker as no reprojecting is necessary). Currently only works for simple features.

...

additional arguments passed on to repective functions. See addRasterImage, addCircles, addPolygons, addPolylines for details

zcol

attribute name(s) or column number(s) in attribute table of the column(s) to be rendered. See also Details.

burst

whether to show all (TRUE) or only one (FALSE) layer(s). See also Details.

color

color (palette) for points/polygons/lines

cex

attribute name(s) or column number(s) in attribute table of the column(s) to be used for defining the size of circles

lwd

line width

alpha

opacity of lines

na.alpha

opacity of missing values

popup

a list of HTML strings with the popup contents, usually created from popupTable. See addControl for details.

label

a character vector of labels to be shown on mouseover. See addControl for details.

highlight

either FALSE, NULL or a list of styling options for feature highlighting on mouse hover. See highlightOptions for details.

maxpoints

the maximum number of points making up the geometry. In case of lines and polygons this refers to the number of vertices. See Details for more information.

y

numeric vector.

type

whether to render the numeric vector x as a point "p" or line "l" plot.

grid

whether to plot a (scatter plot) xy-grid to aid interpretation of the visualisation. Only relevant for the data.frame method.

xcol

the column to be mapped to the x-axis. Only relevant for the data.frame method.

ycol

the column to be mapped to the y-axis. Only relevant for the data.frame method.

aspect

the ratio of x/y axis corrdinates to adjust the plotting space to fit the screen. Only relevant for the data.frame method.

Details

If zcol is not NULL but a length one character vector (referring to a column name of the attribute table) and burst is TRUE, one layer for each unique value of zcol will be drawn. The same will happen if burst is a length one character vector (again referring to a column of the attribute table).

The usage of big data sets is performed by loading local copies of json files from temporary storage. This works fine for most of the current browsers. If you are using Google's chrome browser you have to start the browser with the flag -allow-file-access-from-files (i.e for windows: "path_to_your_chrome_installation\chrome.exe --allow-file-access-from-files", for linux: "/usr/bin/google-chrome --allow-access-from-files"). See http://www.chrome-allow-file-access-from-file.com/ for further details.

NOTE: if XYZ or XYM or XYZM data from package sf is passed to mapview, domensions Z and M will be stripped to ensure smooth rendering even though the popup will potentially still say something like "POLYGON Z".

maxpoints is taken to determine when to switch rendering from svg to canvas overlay for perfomance. The threshold calculation is done as follows: if the number of points (in case of point data) or vertices (in case of polygon or line data) > maxpoints then render using special render function. Within this render function we approximate the complexity of fetures by

maxFeatures <- maxfeatures / (npts(data) / length(data))

where npts determines the umber of points/vertices and length the number of features (points, lines or polygons). When the number of fetures in the current view window is larger than maxFeatures then features are rendered on the canvas, otherwise they are rendered as svg objects and fully queriable.

Methods (by class)

Aliases
  • mapView
  • mapView,RasterLayer-method
  • mapView,RasterStackBrick-method
  • mapView,Satellite-method
  • mapView,sf-method
  • mapView,sfc-method
  • mapView,numeric-method
  • mapView,data.frame-method
  • mapView,XY-method
  • mapView,XYZ-method
  • mapView,XYM-method
  • mapView,XYZM-method
  • mapView,sfc_POINT-method
  • mapView,sfc_MULTIPOINT-method
  • mapView,sfc_LINESTRING-method
  • mapView,sfc_MULTILINESTRING-method
  • mapView,sfc_POLYGON-method
  • mapView,sfc_MULTIPOLYGON-method
  • mapView,sfc_GEOMETRY-method
  • mapView,bbox-method
  • mapView,missing-method
  • mapView,list-method
  • mapview,ANY-method
  • mapview
  • mapView,SpatialPixelsDataFrame-method
  • mapView,SpatialGridDataFrame-method
  • mapView,SpatialPointsDataFrame-method
  • mapView,SpatialPoints-method
  • mapView,SpatialPolygonsDataFrame-method
  • mapView,SpatialPolygons-method
  • mapView,SpatialLinesDataFrame-method
  • mapView,SpatialLines-method
Examples
# NOT RUN {
mapview()

## simple features ====================================================
# sf
mapview(breweries)
mapview(franconia)

# sfc
mapview(st_geometry(breweries)) # no popup

# sfg / XY - taken from ?sf::st_point
outer = matrix(c(0,0,10,0,10,10,0,10,0,0),ncol=2, byrow=TRUE)
hole1 = matrix(c(1,1,1,2,2,2,2,1,1,1),ncol=2, byrow=TRUE)
hole2 = matrix(c(5,5,5,6,6,6,6,5,5,5),ncol=2, byrow=TRUE)
pts = list(outer, hole1, hole2)
(pl1 = st_polygon(pts))
mapview(pl1)

## raster ==============================================================
mapview(poppendorf[[5]])

## spatial objects =====================================================
mapview(leaflet::gadmCHE)
mapview(atlStorms2005)


## styling options & legends ===========================================
mapview(cantons, color = "white", col.regions = "red")
mapview(cantons, color = "magenta", col.regions = "white")

mapview(breweries, zcol = "founded")
mapview(breweries, zcol = "founded", at = seq(1400, 2200, 200), legend = TRUE)
mapview(cantons, zcol = "NAME_1", legend = TRUE)

library(RColorBrewer)
clrs <- colorRampPalette(brewer.pal(9, "Blues"))
mapview(breweries, zcol = "founded", col.regions = clrs, legend = TRUE)

### multiple layers ====================================================
mapview(franconia) + breweries
mapview(list(breweries, franconia))
mapview(breweries) + mapview(franconia) + stormtracks

mapview(franconia, zcol = "district") + mapview(breweries, zcol = "village")
mapview(list(franconia, breweries),
        zcol = list("district", NULL),
        legend = list(TRUE, FALSE))


### burst ==============================================================
mapview(franconia, burst = TRUE)
mapview(franconia, burst = TRUE, hide = TRUE)
mapview(franconia, zcol = "district", burst = TRUE)


### ceci constitue la fin du pipe ======================================
library(dplyr)
library(sf)

franconia %>%
  sf::st_union() %>%
  mapview()

franconia %>%
  group_by(district) %>%
  summarize() %>%
  mapview(zcol = "district")

franconia %>%
  group_by(district) %>%
  summarize() %>%
  mutate(area = st_area(.) / 1e6) %>%
  mapview(zcol = "area")

franconia %>%
  mutate(area = sf::st_area(.)) %>%
  mapview(zcol = "area", legend = TRUE)

breweries %>%
  st_intersection(franconia) %>%
  mapview(zcol = "district")

franconia %>%
  mutate(count = lengths(st_contains(., breweries))) %>%
  mapview(zcol = "count")

franconia %>%
  mutate(count = lengths(st_contains(., breweries)),
         density = count / st_area(.)) %>%
  mapview(zcol = "density")

# }
# NOT RUN {
# }
Documentation reproduced from package mapview, version 2.2.0, License: GPL (>= 3) | file LICENSE

Community examples

Looks like there are no examples yet.