代码之家  ›  专栏  ›  技术社区  ›  Ahmed El-Gabbas

将R'光栅保存到netcdf。保留CRS信息的nc文件

  •  2
  • Ahmed El-Gabbas  · 技术社区  · 7 年前

    我在将光栅对象转换为NetCDF(.nc)文件时遇到问题,无法将CRS信息保留在输出文件中。

    以下是一个可复制的代码:

    require(raster)
    require(ncdf4)
    CurrTemp <- tempfile()
    download.file(url = "https://seaice.uni-bremen.de/data/amsre/asi_daygrid_swath/s6250/2003/feb/Antarctic/asi-s6250-20030214-v5.hdf", destfile = CurrTemp, mode = "wb", quiet = T)
    r <- raster(CurrTemp)
    r <- flip(r,2)
    extent(r) <- c(-3950000, 3950000, -3950000, 4350000)
    crs(r) <- "+proj=stere +lat_0=-90 +lat_ts=-70 +lon_0=0 +k=1 +x_0=0 +y_0=0 +a=6378273 +b=6356889.449 +units=m +no_defs "
    r
    # class       : RasterLayer 
    # dimensions  : 1328, 1264, 1678592  (nrow, ncol, ncell)
    # resolution  : 6250, 6250  (x, y)
    # extent      : -3950000, 3950000, -3950000, 4350000  (xmin, xmax, ymin, ymax)
    # coord. ref. : +proj=stere +lat_0=-90 +lat_ts=-70 +lon_0=0 +k=1 +x_0=0 +y_0=0 +a=6378273 +b=6356889.449 +units=m +no_defs 
    # data source : in memory
    # names       : layer 
    # values      : 0, 100  (min, max)
    

    到目前为止,光栅对象读取效果良好,包括CRS信息。

    然而,当我试图将其保存为。nc文件R打印“坐标参考:NA”,生成的文件不包含CRS信息。

    writeRaster(r, filename = "O:/Ahmed/r001.nc", varname="IceConc",
                overwrite=TRUE, format="CDF",
                xname="Longitude", yname="Latitude")
    # class       : RasterLayer 
    # dimensions  : 1328, 1264, 1678592  (nrow, ncol, ncell)
    # resolution  : 6250, 6250  (x, y)
    # extent      : -3950000, 3950000, -3950000, 4350000  (xmin, xmax, ymin, ymax)
    # coord. ref. : NA 
    # data source : O:/Ahmed/r001.nc 
    # names       : IceConc 
    # zvar        : IceConc
    
    
    raster("O:/Ahmed/r001.nc")
    # class       : RasterLayer 
    # dimensions  : 1328, 1264, 1678592  (nrow, ncol, ncell)
    # resolution  : 6250, 6250  (x, y)
    # extent      : -3950000, 3950000, -3950000, 4350000  (xmin, xmax, ymin, ymax)
    # coord. ref. : NA 
    # data source : O:/Ahmed/r001.nc 
    # names       : IceConc 
    # zvar        : IceConc
    

    谢谢

    0 回复  |  直到 7 年前