问题描述
我正在尝试下载和可视化肯尼亚(以及其他类似国家)的NDVI数据.
I am trying to download and visualise the NDVI data in Kenya (and other countries similarly).
为此,我使用 osmdata
检索了肯尼亚的边界框,并在从 MODIStsp
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
推荐答案
此行为的原因是参数 spatmeth
的默认值为"tiles"
,因此,使用参数 start_x
, end_x
, start_y
和 end_y
指定的值(如果未明确指定,则为其默认值)).
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.
从功能文档中获取:
要使用 kenya_bb
范围,您必须:
- 添加
spatmeth ="tiles"
; - 正确的
bbox = kenya_bb
到bbox = as.vector(kenya_bb)
此外,有一个影响此案的错误,最近已修复.您还应该从GitHub重新安装该软件包:
Moreover, there was a bug affecting this case, recently fixed.You should also reinstall the package from GitHub:
remotes::install_github("ropensci/MODIStsp")
这篇关于可视化特定国家/地区的MODIS植被层(使用R-package MODISttsp)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!