Visualising MODIS Vegetation layers for a specific country (using R-package MODISttsp)

112 Views Asked by At

I am trying to download and visualise the NDVI data in Kenya (and other countries similarly).

For this, I retrieved the bounding box for Kenya using osmdata and used this when downloading NDVI data from MODIStsp

library(osmdata)
library(MODIStsp)

kenya_bb <- osmdata::getbb("Kenya")

MODIStsp(gui             = FALSE,
         out_folder      = "Data",
         out_folder_mod  = "Data",
         selprod         = "Vegetation_Indexes_16Days_1Km (M*D13A2)",
         bbox            =  kenya_bb,
         bandsel         = "NDVI",
         user            = "mstp_test" ,
         password        = "MSTP_test_01",
         start_date      = "2020.06.01", 
         end_date        = "2020.06.15", 
         verbose         = FALSE)

Then I simply visualised the downloaded data, but it hasn't seemed to crop out Kenya

library(raster)
library(here)
library(ggplot2)

NDVI_raster <- raster(here::here("Data/VI_16Days_1Km_v6/NDVI/MOD13A2_NDVI_2020_161.tif"))

NDVI_df <- as.data.frame(NDVI_raster, xy = TRUE, na.rm = TRUE)
rownames(NDVI_df) <- c()

ggplot(data = NDVI_df,
       aes(x=x,y=y)) +
  geom_raster(aes(fill = MOD13A2_NDVI_2020_161))

Any ideas on how to crop out single countries are appreciated

1

There are 1 best solutions below

0
On

The reason of this behaviour is that the default value of argument spatmeth is "tiles", so values specified with arguments start_x, end_x, start_y and end_y (and, if not explicitly specified, their defaults) are used.

From the function documentation:

bbox numeric(4) Output bounding box (xmin, ymin, xmax, ymax) in out_proj coordinate system. Ignored if spatmeth == "tiles", Default: NULL

spatmeth character ["tiles" | "bbox" | "file"], indicates how the processing extent is retrieves. if "tiles", use the specified tiles (start_x....). If "file", retrieve extent from spatial file specifies in spafile. If "bbox", use the specified bounding box, Default: "tiles"

To use the kenya_bb extent you have to:

  1. add spatmeth = "tiles";
  2. correct bbox = kenya_bb to bbox = as.vector(kenya_bb)

Moreover, there was a bug affecting this case, recently fixed. You should also reinstall the package from GitHub:

remotes::install_github("ropensci/MODIStsp")