1

I'm trying to use the MODIStsp R package to download data for a defined country. For this I downloaded the boundary of Mongolia from here into my working directory and passed it's path into my MODIStsp() function. However, this doesn't seem to download the data within the defined boundary and keeps downloading the initial example

spatial_file <- "C:/Users/Zstar/mongolia_administrative_boundaries_national_polygon.shp"

MODIStsp(gui             = FALSE,
         out_folder      = "Data",
         out_folder_mod  = "Data",
         selprod         = "Vegetation_Indexes_16Days_1Km (M*D13A2)",
         spafile         = spatial_file,
         bandsel         = "NDVI", 
         quality_bandsel = "QA_usef", 
         indexes_bandsel = "SR", 
         user            = "mstp_test" ,
         password        = "MSTP_test_01",
         start_date      = "2020.06.01", 
         end_date        = "2020.06.15", 
         verbose         = FALSE)


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

raster <- raster(here("Data/VI_16Days_1Km_v6/NDVI/MOD13A2_NDVI_2020_161.tif"))
df <- as.data.frame(raster, xy = TRUE, na.rm = TRUE)

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

enter image description here

z star
  • 684
  • 6
  • 19
  • were you able to solve this? There seems to similar issue for everyone. See this as well: https://stackoverflow.com/questions/66201309/visualising-modis-vegetation-layers-for-a-specific-country-using-r-package-modi – 89_Simple Mar 30 '21 at 13:01

1 Answers1

0

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, unless spatmeth = "file" is explicited.

From the function documentation:

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"

Adding spatmeth = "file" to MODIStsp() should solve.