Plot a raster object over a map. It can be used to plot tiles from getTiles or images from getPngLayer.

tilesLayer(x, add = FALSE, ...)

pngLayer(x, add = FALSE, ...)

Arguments

x

a RasterBrick object; getPngLayer and getTiles functions output these objects.

add

whether to add the layer to an existing plot (TRUE) or not (FALSE).

...

bgalpha, interpolate, or other arguments passed to be passed to plotRGB

Note

This function is a wrapper for plotRGB from the raster package. The accuracy of the final plot depends on the quality of the *.png file, the scale of x and the resolution setup of the graphic device.

See also

Examples

library(sf) mtq <- st_read(system.file("gpkg/mtq.gpkg", package = "cartography"))
#> Reading layer `mtq' from data source `/tmp/Rtmpe1NJW9/temp_libpathb2e69cc94c1/cartography/gpkg/mtq.gpkg' using driver `GPKG' #> Simple feature collection with 34 features and 7 fields #> geometry type: MULTIPOLYGON #> dimension: XY #> bbox: xmin: 690574 ymin: 1592536 xmax: 735940.2 ymax: 1645660 #> CRS: 32620
if (FALSE) { # Download the tiles, extent = Martinique mtqOSM <- getTiles(x = mtq, type = "osm", crop = TRUE) # Plot the tiles tilesLayer(mtqOSM) # Plot countries plot(st_geometry(mtq), add=TRUE) txt <- "© OpenStreetMap contributors. Tiles style under CC BY-SA, www.openstreetmap.org/copyright" mtext(text = txt, side = 1, adj = 0, cex = 0.7, font = 3) } # Local image dirpng <- system.file("img/LogoMartinique.png", package = "cartography") mask <- getPngLayer(mtq, dirpng, crop = TRUE, margin = 0.5) par(mar = c(0,0,0,0)) ghostLayer(mtq)
pngLayer(mask, add = TRUE)
if (FALSE) { # Remote image urlpng = "https://i.imgur.com/gePiDvB.png" masksea <- getPngLayer(mtq, urlpng, mode = "wb", inverse = TRUE, margin = 0.5) #Combine par(mar = c(0,0,0,0)) ghostLayer(mtq) pngLayer(mask, add = TRUE) pngLayer(masksea, add = TRUE) plot(st_geometry(mtq), border="orange", add=TRUE) }