Convert tidy MODISTools data to a terra SpatRaster for easy spatial processing and plotting.
mt_to_terra(df, reproject = FALSE, method = "bilinear")
a valid MODISTools data frame with a single band (filter for a
particular band using the dplyr filter()
function or base subset()
reproject output to lat / long (default = FALSE
)
character. Method used for estimating the new cell values of a SpatRaster. One of: near: nearest neighbor. This method is fast, and it can be the preferred method if the cell values represent classes. It is not a good choice for continuous values. This is used by default if the first layer of x is categorical. bilinear: bilinear interpolation. This is the default if the first layer of x is numeric (not categorical). cubic: cubic interpolation. cubicspline: cubic spline interpolation.
A terra SpatRaster populated with the tidy dataframe values
# \donttest{
# list all available MODIS Land Products Subsets products
# download data
LC <- mt_subset(product = "MCD12Q1",
lat = 48.383662,
lon = 2.610250,
band = "LC_Type1",
start = "2005-01-01",
end = "2005-12-30",
km_lr = 2,
km_ab = 2,
site_name = "testsite",
internal = TRUE,
progress = FALSE)
head(LC)
#> xllcorner yllcorner cellsize nrows ncols band units scale
#> 1.1 190884.84 5378134.05 463.312716528 9 9 LC_Type1 class Not Available
#> 1.2 190884.84 5378134.05 463.312716528 9 9 LC_Type1 class Not Available
#> 1.3 190884.84 5378134.05 463.312716528 9 9 LC_Type1 class Not Available
#> 1.4 190884.84 5378134.05 463.312716528 9 9 LC_Type1 class Not Available
#> 1.5 190884.84 5378134.05 463.312716528 9 9 LC_Type1 class Not Available
#> 1.6 190884.84 5378134.05 463.312716528 9 9 LC_Type1 class Not Available
#> latitude longitude site product start end complete
#> 1.1 48.38366 2.61025 testsite MCD12Q1 2005-01-01 2005-12-30 TRUE
#> 1.2 48.38366 2.61025 testsite MCD12Q1 2005-01-01 2005-12-30 TRUE
#> 1.3 48.38366 2.61025 testsite MCD12Q1 2005-01-01 2005-12-30 TRUE
#> 1.4 48.38366 2.61025 testsite MCD12Q1 2005-01-01 2005-12-30 TRUE
#> 1.5 48.38366 2.61025 testsite MCD12Q1 2005-01-01 2005-12-30 TRUE
#> 1.6 48.38366 2.61025 testsite MCD12Q1 2005-01-01 2005-12-30 TRUE
#> modis_date calendar_date tile proc_date pixel value
#> 1.1 A2005001 2005-01-01 h18v04 2022153213513 1 5
#> 1.2 A2005001 2005-01-01 h18v04 2022153213513 2 5
#> 1.3 A2005001 2005-01-01 h18v04 2022153213513 3 5
#> 1.4 A2005001 2005-01-01 h18v04 2022153213513 4 5
#> 1.5 A2005001 2005-01-01 h18v04 2022153213513 5 5
#> 1.6 A2005001 2005-01-01 h18v04 2022153213513 6 5
# convert to raster
LC_r <- mt_to_terra(df = LC)
# }