points_to_raster: Bin spatial points to a raster

Description Usage Arguments Details Value See Also Examples

Description

Bin spatial points to a raster. For each raster cell, the number of points are counted. Optionally, a factor variable can be specified by which the points are counts are split. Note that this function supports sf objects, but still uses sp-based methods (see details).

Usage

1
2
points_to_raster(shp, nrow = NA, ncol = NA, N = 250000, by = NULL,
  to.Raster = NULL)

Arguments

shp

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

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.

by

name of a data variable which should be a factor. The points are split and counted according to the levels of this factor.

to.Raster

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

Details

This function is a wrapper around rasterize.

This function supports sf objects, but still uses sp-based methods, from the packages sp, rgeos, and/or rgdal.

Value

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

See Also

poly_to_raster

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## Not run: 
if (require(tmap)) {
    data(NLD_muni, NLD_prov)

    # sample points (each point represents 1000 people)
    NLD_muni_points <- sample_dots(NLD_muni, vars = "population",
        w=1000, convert2density = TRUE)

    # dot map
    tm_shape(NLD_muni_points) + tm_dots()

    # convert points to raster
    NLD_rst <- points_to_raster(NLD_muni_points, N = 1e4)

    # plot raster
    tm_shape(NLD_rst) +
    	tm_raster() +
    tm_shape(NLD_prov) +
    	tm_borders() +
    tm_format("NLD") + tm_style("grey")
}

## End(Not run)

mtennekes/oldtmaptools documentation built on May 11, 2019, 8:22 p.m.