ropensci / MODIStsp

An "R" package for automatic download and preprocessing of MODIS Land Products Time Series
https://docs.ropensci.org/MODIStsp
GNU General Public License v3.0
155 stars 50 forks source link

bounding box does not work #234

Closed kuntalnr closed 3 years ago

kuntalnr commented 3 years ago

Issue description

Reproducible example

## PLEASE DELETE AND WRITE YOUR OWN
library(MODIStsp)
library(osmdata)
# I expect the below code to give me tiles covering China but gives me a default tile which
# I don't know which geographical region it is
china_bb <- osmdata::getbb("China")

MODIStsp(gui             = FALSE,
         selcat          = "Ecosystem Variables - Vegetation Indices",
         selprod         = "Vegetation_Indexes_16Days_1Km (M*D13A2)",
         bbox            =  china_bb,
         sensor          = "Terra",
         bandsel         = "EVI",
         download_server = "http",
         user            = "XXXX" ,
         password        = "XXXX",
         start_date      = "2001.02.18", 
         end_date        = "2001.12.31", 
         out_projsel     = "User Defined",
         output_proj     = "4326",
         out_res_sel     = "Native",
         out_res         = 926.6254,
         resampling      = "near",
         reprocess       = FALSE,
         delete_hdf      = TRUE,
         nodata_change   = FALSE,
         scale_val       = TRUE,
         out_format      = "GTiff",
         compress        = "LZW",
         out_folder      = "D:/modis",
         out_folder_mod  = "D:/modis_hdf"
)

Expected and actual behavior

# If I read a single file, as follows, I get a tile which is not China.

library(raster)
temp <- raster('D:/modis/VI_16Days_1Km_v6/EVI/MOD13A2_EVI_2000_049.tif')
plot(temp)

# This issue is also being asked on SO here   

#https://stackoverflow.com/questions/66326127/using-a-shapefile-with-modistsp-r-package  

#https://stackoverflow.com/questions/66201309/visualising-modis-vegetation-layers-for-a-
specific-country-using-r-package-modi

System information

R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows Server 2012 R2 x64 (build 9600)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] osmdata_0.1.5  MODIStsp_2.0.5

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.5          compiler_4.0.2      pillar_1.4.6        xts_0.12.1          bitops_1.0-6        class_7.3-17       
 [7] tools_4.0.2         lubridate_1.7.9     jsonlite_1.7.0      lifecycle_0.2.0     tibble_3.0.3        lattice_0.20-41    
[13] pkgconfig_2.0.3     rlang_0.4.10        DBI_1.1.0           rstudioapi_0.11     rgdal_1.5-16        curl_4.3           
[19] parallel_4.0.2      xfun_0.19           e1071_1.7-3         xml2_1.3.2          stringr_1.4.0       dplyr_1.0.1        
[25] httr_1.4.2          raster_3.3-13       generics_0.0.2      vctrs_0.3.2         gdalUtilities_1.1.1 classInt_0.4-3     
[31] grid_4.0.2          tidyselect_1.1.0    glue_1.4.2          data.table_1.13.0   sf_0.9-5            R6_2.4.1           
[37] sp_1.4-2            purrr_0.3.4         magrittr_2.0.1      codetools_0.2-16    ellipsis_0.3.1      units_0.6-7        
[43] rvest_0.3.6         assertthat_0.2.1    KernSmooth_2.23-17  tinytex_0.27        stringi_1.4.6       crayon_1.3.4       
[49] zoo_1.8-8 

‘2.0.5’

Additional context

Scientific publication

ranghetti commented 3 years ago

Sorry for waiting. 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 china_bb extent you have to:

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

Moreover, there was a bug (fixed with c22cc9672c8deb156a1a34d4165f4a1f80cda46a) affecting your case. You should also reinstall the package from GitHub:

remotes::install_github("ropensci/MODIStsp")