rasterizePoints: Convert point data to gridded data

View source: R/rasterizePoints.R

rasterizePointsR Documentation

Convert point data to gridded data

Description

Turn a dataframe or SpatiaPointsDataFrame into a RasterLayer or RasterStack with a certain resolution and certain extent.

Usage

rasterizePoints(
  data,
  long = NA,
  lat = NA,
  res = 0.5,
  tres = NA,
  ...,
  crop = T,
  crs = sp::CRS("+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0")
)

Arguments

data

SpatialPointsDataFrame or dataframe

long

character specifying name of Longitude column.

lat

character specifying name of Latitude column.

res

Desired resolution for ridded output data

tres

Desired temporal resolution

...

Additional arguments for rasterize function.

crop

logical. Crop raster by bounding box of SpatialPoints, default is FALSE.

crs

projection of input data, if data is not a SpatialPointsDataFrame

Value

rasterstack with data

Examples

data(meuse, package="sp")
library(ggplot2)
ggplot(aes(x = x, y = y, color = zinc), data = meuse) + 
geom_point() + theme(legend.position=c(0.85,0.2))

gr_meuse <- rasterizePoints(data=meuse, res=100, crs=sp::CRS("+init=epsg:28992"))
library(raster)
ggplot(aes(x = x, y = y, fill = cadmium), data = data.frame(rasterToPoints(gr_meuse))) + 
geom_raster()

# If long and lat are not called x,y, 
# you have to specify their columnNames 
# in the rasterizePoints function accordingly
meuse_longlat <- meuse
colnames(meuse_longlat)[c(1,2)] <- c("Longitude", "Latitude")

gr_meuse <- rasterizePoints(data=meuse_longlat, long="Longitude", lat="Latitude", 
                            res=100, crs=sp::CRS("+init=epsg:28992"))
ggplot(aes(x = x, y = y, fill = lead), data = data.frame(rasterToPoints(gr_meuse))) + 
geom_raster()


RS-eco/rasterSp documentation built on Jan. 24, 2023, 12:06 a.m.