7.7 Reprojecting raster:

  • create a new raster object (with different rows/cols)

  • resampling values of every cell (using different resamploing methods)

Terra’s function project() allow you to do that.

As usual: nearest neighbour method are good for categorical data. You have more option for quantitative data.

cat_raster = rast(system.file("raster/nlcd.tif", package = "spDataLarge"))
crs(cat_raster) |> cat()
## PROJCRS["NAD83 / UTM zone 12N",
##     BASEGEOGCRS["NAD83",
##         DATUM["North American Datum 1983",
##             ELLIPSOID["GRS 1980",6378137,298.257222101,
##                 LENGTHUNIT["metre",1]]],
##         PRIMEM["Greenwich",0,
##             ANGLEUNIT["degree",0.0174532925199433]],
##         ID["EPSG",4269]],
##     CONVERSION["UTM zone 12N",
##         METHOD["Transverse Mercator",
##             ID["EPSG",9807]],
##         PARAMETER["Latitude of natural origin",0,
##             ANGLEUNIT["degree",0.0174532925199433],
##             ID["EPSG",8801]],
##         PARAMETER["Longitude of natural origin",-111,
##             ANGLEUNIT["degree",0.0174532925199433],
##             ID["EPSG",8802]],
##         PARAMETER["Scale factor at natural origin",0.9996,
##             SCALEUNIT["unity",1],
##             ID["EPSG",8805]],
##         PARAMETER["False easting",500000,
##             LENGTHUNIT["metre",1],
##             ID["EPSG",8806]],
##         PARAMETER["False northing",0,
##             LENGTHUNIT["metre",1],
##             ID["EPSG",8807]]],
##     CS[Cartesian,2],
##         AXIS["(E)",east,
##             ORDER[1],
##             LENGTHUNIT["metre",1]],
##         AXIS["(N)",north,
##             ORDER[2],
##             LENGTHUNIT["metre",1]],
##     USAGE[
##         SCOPE["Engineering survey, topographic mapping."],
##         AREA["North America - between 114°W and 108°W - onshore and offshore. Canada - Alberta; Northwest Territories; Nunavut; Saskatchewan. United States (USA) - Arizona; Colorado; Idaho; Montana; New Mexico; Utah; Wyoming."],
##         BBOX[31.33,-114,84,-108]],
##     ID["EPSG",26912]]
cat_raster_wgs84 = project(cat_raster, "EPSG:4326", method = "near")
cat_raster_wgs84
## class       : SpatRaster 
## dimensions  : 1246, 1244, 1  (nrow, ncol, nlyr)
## resolution  : 0.0003150638, 0.0003150638  (x, y)
## extent      : -113.2414, -112.8495, 37.12656, 37.51913  (xmin, xmax, ymin, ymax)
## coord. ref. : lon/lat WGS 84 (EPSG:4326) 
## source(s)   : memory
## color table : 1 
## categories  : levels 
## name        :   levels 
## min value   :    Water 
## max value   : Wetlands
cat_raster
## class       : SpatRaster 
## dimensions  : 1359, 1073, 1  (nrow, ncol, nlyr)
## resolution  : 31.5303, 31.52466  (x, y)
## extent      : 301903.3, 335735.4, 4111244, 4154086  (xmin, xmax, ymin, ymax)
## coord. ref. : NAD83 / UTM zone 12N (EPSG:26912) 
## source      : nlcd.tif 
## color table : 1 
## categories  : levels 
## name        :   levels 
## min value   :    Water 
## max value   : Wetlands