poly_to_raster: Convert spatial polygons to a raster

Description Usage Arguments Value See Also Examples

View source: R/to_raster.R

Description

Convert spatial polygons to a raster. The value of each raster cell will be the polygon ID number. Alternatively, if copy.data, the polygon data is appended to each raster cell.

Usage

1
2
poly_to_raster(shp, r = NULL, nrow = NA, ncol = NA, N = 250000,
  use.cover = FALSE, copy.data = FALSE, to.Raster = NULL, ...)

Arguments

shp

shape object. A SpatialPoints(DataFrame), a SpatialGrid(DataFrame), or an sf object that can be coerced as such.

r

Raster object. If not specified, it will be created from the bounding box of shp and the arguments N, nrow, and ncol.

nrow

number of raster rows. If NA, it is automatically determined by N and the aspect ratio of shp.

ncol

number of raster columns. If NA, it is automatically determined by N and the aspect ratio of shp.

N

preferred number of raster cells.

use.cover

logical; should the cover method be used? This method determines per raster cell which polygon has the highest cover fraction. This method is better, but very slow, since N times the number of polygons combinations are processed (using the getCover argument of rasterize). By default, when a raster cell is covered by multiple polygons, the last polygon is taken (see fun argment of rasterize))

copy.data

should the polygon data be appended to the raster? Only recommended when N is small.

to.Raster

not used anymore, since the "raster" output is always a RasterLayer as of version 2.0

...

arguments passed on to rasterize

Value

a RasterBrick is returned when by is specified, and a RasterLayer when by is unspecified

See Also

points_to_raster

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
## Not run: 
if (require(tmap)) {
    data(NLD_muni)

    # choropleth of 65+ population percentages
    qtm(NLD_muni, fill="pop_65plus", format="NLD")

    # rasterized version
    NLD_rst <- poly_to_raster(NLD_muni, copy.data = TRUE)
    qtm(NLD_rst, raster="pop_65plus", format="NLD")
}

## End(Not run)

tmaptools documentation built on Aug. 9, 2018, 9:04 a.m.