I've got most of the steps for manipulating netCDF files using packages ncdf and raster but I'm currently stuck getting the correct projection information (lat/long) over to the raster and then exporting it.   
 
Here's a VERY simply netCDF raster (2 cells lat X 2 cells long X 3 time periods) and how I might grab one of those time periods (I tried using dput to actually provide the data, but couldn't get dget to re-load it, I'd be happy to supply data if someone can suggest how). 
 
> library(ncdf)
> library(raster)
> ncTemp2 <- open.ncdf("Extraction_Tavg.nc")
> ncTemp2
[1] "file Extraction_Tavg.nc has 4 dimensions:"
[1] "time   Size: 3"
[1] "latitude   Size: 2"
[1] "longitude   Size: 2"
[1] "projection   Size: 1"
[1] "------------------------"
[1] "file Extraction_Tavg.nc has 1 variables:"
[1] "float Tavg[longitude,latitude,time,projection]  Longname:Tavg Missval:1.00000002004088e+20"
> str(ncTemp2)
List of 10
 $ id          : int 3
 $ ndims       : int 4
 $ natts       : int 10
 $ unlimdimid  : num 4
 $ filename    : chr "Extraction_Tavg.nc"
 $ varid2Rindex: num [1:4] 0 0 0 1
 $ writable    : logi FALSE
 $ dim         :List of 4
  ..$ time      :List of 8
  .. ..$ name         : chr "time"
  .. ..$ len          : int 3
  .. ..$ unlim        : logi FALSE
  .. ..$ id           : int 1
  .. ..$ dimvarid     : num 1
  .. ..$ units        : chr "days since 1950-01-01 00:00:00"
  .. ..$ vals         : num [1:3(1d)] 15 46 73
  .. ..$ create_dimvar: logi TRUE
  .. ..- attr(*, "class")= chr "dim.ncdf"
  ..$ latitude  :List of 8
  .. ..$ name         : chr "latitude"
  .. ..$ len          : int 2
  .. ..$ unlim        : logi FALSE
  .. ..$ id           : int 2
  .. ..$ dimvarid     : num 2
  .. ..$ units        : chr "degrees_north"
  .. ..$ vals         : num [1:2(1d)] 42.1 42.2
  .. ..$ create_dimvar: logi TRUE
  .. ..- attr(*, "class")= chr "dim.ncdf"
  ..$ longitude :List of 8
  .. ..$ name         : chr "longitude"
  .. ..$ len          : int 2
  .. ..$ unlim        : logi FALSE
  .. ..$ id           : int 3
  .. ..$ dimvarid     : num 3
  .. ..$ units        : chr "degrees_east"
  .. ..$ vals         : num [1:2(1d)] -74.2 -74.1
  .. ..$ create_dimvar: logi TRUE
  .. ..- attr(*, "class")= chr "dim.ncdf"
  ..$ projection:List of 8
  .. ..$ name         : chr "projection"
  .. ..$ len          : int 1
  .. ..$ unlim        : logi TRUE
  .. ..$ id           : int 4
  .. ..$ dimvarid     : int -1
  .. ..$ vals         : int 1
  .. ..$ units        : chr ""
  .. ..$ create_dimvar: logi FALSE
  .. ..- attr(*, "class")= chr "dim.ncdf"
 $ nvars       : num 1
 $ var         :List of 1
  ..$ Tavg:List of 16
  .. ..$ id          : int 4
  .. ..$ name        : chr "Tavg"
  .. ..$ ndims       : int 4
  .. ..$ natts       : int 6
  .. ..$ size        : int [1:4] 2 2 3 1
  .. ..$ prec        : chr "float"
  .. ..$ dimids      : num [1:4] 3 2 1 4
  .. ..$ units       : chr "C"
  .. ..$ longname    : chr "Tavg"
  .. ..$ dims        : list()
  .. ..$ dim         :List of 4
  .. .. ..$ :List of 8
  .. .. .. ..$ name         : chr "longitude"
  .. .. .. ..$ len          : int 2
  .. .. .. ..$ unlim        : logi FALSE
  .. .. .. ..$ id           : int 3
  .. .. .. ..$ dimvarid     : num 3
  .. .. .. ..$ units        : chr "degrees_east"
  .. .. .. ..$ vals         : num [1:2(1d)] -74.2 -74.1
  .. .. .. ..$ create_dimvar: logi TRUE
  .. .. .. ..- attr(*, "class")= chr "dim.ncdf"
  .. .. ..$ :List of 8
  .. .. .. ..$ name         : chr "latitude"
  .. .. .. ..$ len          : int 2
  .. .. .. ..$ unlim        : logi FALSE
  .. .. .. ..$ id           : int 2
  .. .. .. ..$ dimvarid     : num 2
  .. .. .. ..$ units        : chr "degrees_north"
  .. .. .. ..$ vals         : num [1:2(1d)] 42.1 42.2
  .. .. .. ..$ create_dimvar: logi TRUE
  .. .. .. ..- attr(*, "class")= chr "dim.ncdf"
  .. .. ..$ :List of 8
  .. .. .. ..$ name         : chr "time"
  .. .. .. ..$ len          : int 3
  .. .. .. ..$ unlim        : logi FALSE
  .. .. .. ..$ id           : int 1
  .. .. .. ..$ dimvarid     : num 1
  .. .. .. ..$ units        : chr "days since 1950-01-01 00:00:00"
  .. .. .. ..$ vals         : num [1:3(1d)] 15 46 73
  .. .. .. ..$ create_dimvar: logi TRUE
  .. .. .. ..- attr(*, "class")= chr "dim.ncdf"
  .. .. ..$ :List of 8
  .. .. .. ..$ name         : chr "projection"
  .. .. .. ..$ len          : int 1
  .. .. .. ..$ unlim        : logi TRUE
  .. .. .. ..$ id           : int 4
  .. .. .. ..$ dimvarid     : int -1
  .. .. .. ..$ vals         : int 1
  .. .. .. ..$ units        : chr ""
  .. .. .. ..$ create_dimvar: logi FALSE
  .. .. .. ..- attr(*, "class")= chr "dim.ncdf"
  .. ..$ varsize     : int [1:4] 2 2 3 1
  .. ..$ unlim       : logi TRUE
  .. ..$ missval     : num 1e+20
  .. ..$ hasAddOffset: logi FALSE
  .. ..$ hasScaleFact: logi FALSE
  .. ..- attr(*, "class")= chr "var.ncdf"
 - attr(*, "class")= chr "ncdf"
> 
> layr <- get.var.ncdf(ncTemp2, varid="Tavg",start=c(1,1,2,1), count=c(2,2,1,1))
> m <- raster(layr)
> m
class       : RasterLayer 
dimensions  : 2, 2, 4  (nrow, ncol, ncell)
resolution  : 0.5, 0.5  (x, y)
extent      : 0, 1, 0, 1  (xmin, xmax, ymin, ymax)
coord. ref. : NA 
values      : in memory
min value   : -7.36 
max value   : -4.35 
 
 
My Question: How do I now export the single raster, m, so that I can bring along all the relevant spatial information contained in the netCDF (which would be the lat long coordinates?).   I'd like to export the raster into any format accessible by esri products (boo!). 
 
Thanks in advance, 
Tim
 

 

	[[alternative HTML version deleted]]

