【问题标题】:Plotting netcdf file with raster package leads to distorted representation, R用光栅包绘制 netcdf 文件会导致表示失真,R
【发布时间】:2017-06-08 15:41:05
【问题描述】:

我想正确地绘制这个 netcdf 文件:http://www.filedropper.com/sshgridsv16092015060412nc(最初从 here: https://opendap.jpl.nasa.gov/opendap/allData/merged_alt/L4/cdr_grid/contents.html 下载)

但遇到问题:

我应该能够只绘制栅格(SLA 变量):

library(RNetCDF)
library(raster)
library(maptools)

d <- raster("ssh_grids_v1609_2015060412.nc.nc4", varname = "SLA")

plot(d)
#plot SLA

但是从提供的文件中可以看出,结果非常奇怪。

尤其是在顶部绘制世界地图时:

data(wrld_simpl)
plot(wrld_simpl, add = T) 

它们根本不匹配:/

所以我认为问题可能出在经度上(范围从 4.839944e-09 到 360)

然后我读到了 raster::rotate(d)

应该是完美的(将经度提高到 -180 到 180),但它不会让我这样做。我收到此警告消息:

Warning message:
In .local(x, ...) :
  this does not look like an appropriate object for this function

plot(d) 

看起来还是一样。

任何建议将不胜感激!

干杯

【问题讨论】:

    标签: r maps geospatial spatial r-raster


    【解决方案1】:

    Netcdf 文件不仅在经度上“旋转”了,而且 x 和 y 也在错误的位置。它在 netcdf 中的输入方式显然不常见。
    我直接在the OpenDap server 上下载了 netcdf,因为您的 filedropper 链接似乎已损坏。
    无论如何,这是我的提议:

    library(raster)
    library(maptools)
    
    d <- raster("ssh_grids_v1609_2015060412.nc.nc4", varname = "SLA")
    
    # transpose x to y and double flip the map
    m.r <- flip(flip(t(d), direction = "y"), direction = "x")
    
    # then rotate from 0:360 to -180:180
    rm.r <- rotate(m.r)
    
    data(wrld_simpl)
    
    plot(rm.r)
    plot(wrld_simpl, add = T) 
    

    【讨论】:

    • 非常感谢。它似乎工作得很好,但是当我在 RStudio 中单击缩放图时,世界地图和 rm.r 再次关闭。可能还有其他问题吗?干杯
    • 绘制后不应使用光栅对象调整绘图的大小。通常,重绘不适用于栅格。因此,例如使用 x11() 打开一个所需大小的空窗口,然后绘制栅格。
    猜你喜欢
    • 2020-09-27
    • 2016-04-17
    • 1970-01-01
    • 1970-01-01
    • 2015-01-28
    • 1970-01-01
    • 1970-01-01
    • 2011-08-08
    • 2017-01-26
    相关资源
    最近更新 更多