我试图在特定位置提取MODIS辐射数据,但是我的代码始终返回NA。问题似乎是我没有正确使用图块中的位置信息。
我将很高兴获得解决方案的帮助。
{
prod <- "MCD18A2"
lon <- (-93.62)
lat <- 42.03
buffer <- 0.3
dates <- paste0("2011-12-0",1:2)
library(MODIS)
library(rgdal)
library(sp)
# create a spatial object from the coordinate(s)
coordinates = SpatialPoints(coords=cbind(lon, lat), proj4string = CRS('+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0'))
sinus = CRS("+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371007.181 +b=6371007.181 +units=m +no_defs")
# transform the coordinates
coordinates_sinus = spTransform(coordinates, sinus)
e <- extent(lon-buffer, lon+buffer, lat-buffer, lat+buffer)
tileLayer <- getTile(e)
target.file <- getHdf(product=prod,
begin=dates[1],
end=dates[length(dates)],
tileH=tileLayer@tileH,
tileV=tileLayer@tileV,
# extent=tileLayer@extent,
checkIntegrity = FALSE)
# convert to raster
sds <- getSds(as.character(target.file$MCD18A2.006[1]))
hdf_layer = raster(readGDAL(sds$SDS4gdal[1], as.is = TRUE))
# extract data
point = extract(hdf_layer, coordinates_sinus)
}