Skip to content

netCDF to raster

7 messages · Advait Godbole, Michael Sumner, Samuel Veloz +1 more

#
How about this? Requires raster, ncdf, rgdal, and sp packages at least
so they must be installed.

library(raster)
## you will need to set some options here, but there are prompts
r <- raster("ncfile.nc")

sgdf <- as(r, "SpatialGridDataFrame")

writeGDAL(sgdf, "geotiff.tif")

See gdalDrivers() for the available formats, which can be set using
options to writeGDAL.

No doubt there will be variations and extra digging for you particular
data, but not far from this. Can you share the file?

Cheers, Mike.
On Sun, Nov 7, 2010 at 1:19 AM, Advait Godbole <advaitgodbole at gmail.com> wrote:

  
    
#
Dear Advait,

"netcdf does not really have a "projection" in GIS parlance". netcdf
is flexible file format in which you can store all kinds of data in
different ways. Climatologists and some others tend to follow the "CF"
(NetCDF Climate and Forecast Metadata Convention) conventions.
Unfortunately, they do not make use one of the standard projections
description formats. I have not taken the time yet to parse the CF
descriptions and into a proj.4 string. However, the projection
metadata is stored in the raster object that you create from a nc (CF)
file in the slot "prj"

r <- raster('ncfile')
r at prj
prj <- "+proj=lcc +lat_1=33 +lat_2=45 +lat_0=40 +lon_0=-96"

(see http://www.remotesensing.org/geotiff/proj_list/lambert_conic_conformal_2sp.html
)

and do:

projection(r) <- prj

and save the file.

Robert
On Sat, Nov 6, 2010 at 12:51 PM, Advait Godbole <advaitgodbole at gmail.com> wrote: