关于我之前的问题Read/Open Oceancolor data from MODIS with nc format。我尝试使用此代码阅读此处下载的 ncdf oceancolor 数据ncdf4 package
library(ncdf4)
nc <- nc_open('A2014325053500.L2_LAC_SST.nc')
# Get data for each variabel name as a large matrix
sst <- ncvar_get(nc, varid = 'geophysical_data/sst')
lon <- ncvar_get(nc, varid = 'navigation_data/longitude')
lat <- ncvar_get(nc, varid = 'navigation_data/latitude')
比这个数据,我转换为栅格。但我未能重新投影光栅figure 1
。图像应该像figure 2
library(sp)
library(raster)
r <- raster(sst,
xmn=min(lat), xmx=max(lat),
ymn=min(lon), ymx=max(lon),
crs=CRS('+proj=longlat +ellps=WGS84 +datum=WGS84'))
proj='+proj=longlat +ellps=WGS84 +datum=WGS84'
r2 <- projectRaster(r, crs=proj, method = 'ngb')
plot(r2)
根据 jbaums 的第一个建议,结果未正确重新投影figure 3
我只是意识到当我增加分辨率时结果有问题。在西部和东部变成白色(无数据)。我在下面使用了这段代码:
r <- rasterize(df, raster(extent(df), res=0.0103011), 'sst', fun=mean)