getPngLayer {cartography} R Documentation

## .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,
inverse = FALSE,
dwmode = "curl",
...
)


### 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.

### Value

A RasterBrick object is returned.

### Note

The accuracy of the final plot would depend on the quality of the .png file, the scale of x and the resolution setup of the graphic device. Exporting to svg is highly recommended.

### Author(s)

dieghernan, https://github.com/dieghernan/

### Examples

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