Learn R Programming

cartography (version 3.1.4)

getPngLayer: .png Layer

Description

Get a RasterBrick from a .png image cut using the shape of a spatial object. The .png file could be either a local file or extracted from a given url.

Usage

getPngLayer(
  x,
  pngpath,
  align = "center",
  margin = 0,
  crop = FALSE,
  mask = TRUE,
  inverse = FALSE,
  dwmode = "curl",
  ...
)

Value

A RasterBrick object is returned.

Arguments

x

an sf object, a simple feature collection (POLYGON or MULTIPOLYGON) or a tile (see getTiles).

pngpath

local path or url of a .png file.

align

set how the .png file should be fitted within x. Possible values are 'left','right','top', 'bottom' or 'center'.

margin

inner margin, zooms out the .png over x. If 0 then .png is completely zoomed over x.

crop

TRUE if results should be cropped to the specified x extent.

mask

TRUE if the result should be masked to x.

inverse

logical. If FALSE, overlapped areas of x on pngpath are extracted, otherwise non-overlapping areas are returned. See mask.

dwmode

Set the download mode. It could be 'base' for download.file or 'curl' for curl_download.

...

additional arguments for downloading the file. See download.file or curl_download.

Details

The effect of align would differ depending of the aspect ratio of x and pngpath. To obtain a fitted tile from pngpath given that x is the tile to fit, set margin = 0 , crop = TRUE.

See Also

pngLayer

Examples

Run this code
library(sf)
mtq <- st_read(system.file("gpkg/mtq.gpkg", package = "cartography"))
#Local file
dirpng <- system.file("img/LogoMartinique.png", package = "cartography")
mask <- getPngLayer(mtq, dirpng)

if (FALSE) {
#Remote file
urlpng <- "https://i.imgur.com/gePiDvB.png"
masksea <- getPngLayer(mtq, urlpng, mode = "wb", inverse = TRUE)
}

Run the code above in your browser using DataLab