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.
points_to_raster(shp, nrow = NA, ncol = NA, N = 250000, by = NULL,
to.Raster = FALSE)
shape object. a SpatialPoints(DataFrame)
, a SpatialGrid(DataFrame)
, or an sf
object that can be coerced as such.
number of raster rows. If NA
, it is automatically determined by N
and the aspect ratio of shp
.
number of raster columns. If NA
, it is automatically determined by N
and the aspect ratio of shp
.
preferred number of raster cells.
name of a data variable which should be a factor. The points are split and counted according to the levels of this factor.
logical; should the output be a Raster
object (TRUE
), or a SpatialGridDataFrame
(FALSE
). If TRUE
, a RasterBrick
is returned when by
is specified, and a RasterLayer
when by
is unspecified.
A SpatialGridDataFrame
, or a Raster
object when (to.Raster=TRUE
)
This function is a wrapper around rasterize
.
Tennekes, M., 2018, tmap: Thematic Maps in R, Journal of Statistical Software, 84(6), 1-39, DOI
# 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()
}
# }
Run the code above in your browser using DataLab