可视化特定国家/地区的MODIS植被层(使用R-package MODISttsp) [英] Visualising MODIS Vegetation layers for a specific country (using R-package MODISttsp)
问题描述
我正在尝试下载和可视化肯尼亚(以及其他类似国家)的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.
从功能文档中获取:
bbox 数字(4)out_proj坐标系中的输出边界框(xmin,ymin,xmax,ymax).是否忽略spatmeth =="tiles" ,默认值:NULL
bbox numeric(4) Output bounding box (xmin, ymin, xmax, ymax) in out_proj coordinate system. Ignored if spatmeth == "tiles", Default: NULL
spatmeth 字符["tiles"|"bbox"|文件"],指示如何检索处理范围.如果是瓦片",则使用指定的图块(start_x ....).如果是文件",则从空间文件中检索范围在spafile中指定.如果是"bbox",请使用指定的边界框,默认:"tiles"
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"
要使用 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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!