Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am writing a rasterbrick with multiple layers to a netcdf file using the raster package in R:

writeRaster(gridfile, "Data", "CDF", overwrite=TRUE,
     varname="Data",varunit="mm.d-1",longname="Monthly data",
     xname="lon",yname="lat", zname="time", zunit="month",bylayer=FALSE,NAflag=-9999)

Is there a way to have the data with time coordinates in the written ncdf file? E.g. in the NetCDF Viewer Panoply I can plot the data in [lon][lat] but not in [time][lat].

Also how can specify the timesteps as specific months in a year instead of the timesteps starting from 1 and increasing?

share|improve this question
I have found a solution using the ncdf package: However, is there a way to directly do this through the raster package? – Dom Apr 19 '13 at 12:36
Can you add some data, or at least include str(gridfile) and sessionInfo() so we know your R, raster, and ncdf/ncdf4 versions? – mdsumner Apr 22 '13 at 21:20
I wrote that answer and unfortunately I am still looking for a way to add time slices into netcdf files using the raster package. – thiagoveloso Oct 22 '15 at 17:57

You should use the R-Package netcdf package, it has much more possibilities to taylor your resulting data fields. To hold the GIS connectvity use the Lon/Lat attribute schema beside the time attribute (Spatial temporal advises ).

If you want to create and use spatio temporal datasets like in climatology you should read the best practice article of There are several tools which work with netcdf spatio temporal standard structures.

Mapping netcdf - NCL | NCO netCDF-Operator | CDO - Climate Data Operators

NCL Example

enter image description here

Bye Huck

share|improve this answer

Valid units strings for CF-compliant netcdf files look like "seconds since 1970-01-01 00:00:00" or "days since 2013-04-19 00:00:00"

I think "months since ...." isn't supported by udunits since months are not equally sized.

You might do better thinking of the z dimension as a record dimension and then add a time variable with ncdf that locates each record in time.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.