[R-sig-Geo] converting raster to netcdf .nc with keeping CRS information

Ahmed El-Gabbas e|g@b@@@ @end|ng |rom gm@||@com
Tue Feb 12 14:34:59 CET 2019


Hello all,


I am having a problem while converting a raster object as NetCDF (.nc)
file, with keeping the CRS information in the output file.

Here is a reproducible code:

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)

So far the raster object reads well, with CRS information included.

However, when I try to save it as .nc file, R prints "coord. ref. : NA",
and the produced file does not contain the CRS information.

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

Any solution?


N.B. I also sent the same question at stackoverflow
<https://stackoverflow.com/questions/54593552/saving-r-raster-to-netcdf-nc-file-with-keeping-crs-information>,
without a solution so far.


Thanks

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*Dr. Ahmed El-Gabbas,*
Ocean Acoustics Lab,
Alfred-Wegener-Institut
Helmholtz-Zentrum für Polar und Meeresforschung
[image: image.png]
My Website:  https://elgabbas.github.io

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20190212/d2b0ddb9/attachment.html>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 16685 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20190212/d2b0ddb9/attachment.png>


More information about the R-sig-Geo mailing list