r3.out.netcdf(1)

πŸ’– r3.out.netcdf β€” the GRASS GIS User's Manual glow-up πŸ’–

okay bestie, listen up, this is the manual page for r3.out.netcdf(1) and it's lowkey a whole vibe. it's from the GRASS GIS User's Manual, so you know it's legit. no cap. ✨


🌸 NAME 🌸

r3.out.netcdf β€” Export a 3D raster map as netCDF file.


🏷️ KEYWORDS 🏷️

raster3d, export, output, netCDF, voxel


πŸŽ€ SYNOPSIS πŸŽ€

okay so here's the shape of the thing, exactly as it is:

r3.out.netcdf
r3.out.netcdf --help
r3.out.netcdf [-pm] input=name output=name  [null=float]   [--overwrite]
[--help]  [--verbose]  [--quiet]  [--ui]

✨ Flags ✨

like little switches, and each one is doing something, periodt:

  • -p β€” Export projection information as wkt and proj4 parameter
  • -m β€” Use 3D raster mask (if exists) with input map
  • --overwrite β€” Allow output files to overwrite existing files
  • --help β€” Print usage summary
  • --verbose β€” Verbose module output
  • --quiet β€” Quiet module output
  • --ui β€” Force launching GUI dialog

🧚 Parameters 🧚

these are the things you actually gotta hand over:

  • input=name [required] β€” Name of input 3D raster map
  • output=name [required] β€” Name for netCDF output file
  • null=float β€” The value to be used for null values, default is the netCDF standard
bestie the first two are required required. like, you cannot skip them. the module will simply not be having it. 🫢

🌈 DESCRIPTION 🌈

so the module r3.out.netcdf exports a 3D raster map as a netCDF file. the maps it works with are valid 3D raster maps that live in the current mapset search path. πŸ—ΊοΈ

the output parameter is the name of a netCDF file that's gonna get written into the current working directory (yes, where you're standing right now, not somewhere else, iykyk).

this module is sensitive to mapset region settings β€” the ones you set with g.region β€” and also to the vertical unit settings of the 3D raster map. you can set that vertical unit with r3.support. πŸ’…


πŸ“ NOTES πŸ“

kay so here's the tea. β˜•

the resulting netCDF file will have time as the third dimension if a temporal vertical unit is specified for the input map. otherwise, that third dimension is assumed to be spatial. no in-between, it picks one.

if the 3D raster map has a time stamp with absolute time, the start time gets used as the starting point for the netCDF time series. and if that absolute time stamp is missing? then the date Jan. 01. 1900 00:00:00 is used as the default. πŸ•°οΈ and if it's a relative time stamp, no start time is set in the netCDF file at all.

the number of depths of the 3D raster map = the number of time slices in the netCDF file. iconic math.

you can use t.rast.to.rast3 to convert a space time raster dataset into a 3D raster map that represents a space time voxel cube, and then export the raster time series as a netCDF file. obsessed with this pipeline honestly. πŸ”₯

spatial coordinates get exported as cell centered coordinates. the projection can optionally be stored in the metadata as crs attributes. the netCDF projection metadata storage follows the spatial_ref GDAL/netCDF suggestion here and the netCDF CF 1.6 convention here, using WKT projection information. additionally, a PROJ string is stored in the crs attribute section. πŸ“

heads up bestie: the export of projection parameters is suppressed when the XY-projection is set. so don't come looking for them, they're not invited. πŸ™ˆ

the range of the 3D raster map is set in the netCDF output file. optionally, a netCDF missing value and _FillValue can be set using the null option. as default, the netCDF floating point _FillValues are used to fill empty cells. ✨

and finally β€” real talk β€” the netCDF library must be installed on the system and activated at configuration time in order to compile this module. no library, no module, that's just the deal. πŸ’€

✨ EXAMPLES ✨

okay bestie, this is the part where we actually do stuff πŸ’… buckle up, we're building a whole 3D volume from scratch and shipping it out as netCDF. no cap, it's giving tutorial energy and I am obsessed.

First things first β€” set up the region. This is the grid everything else lives on:

g.region s=-90 n=90 w=-180 e=180 b=0 t=5 res=10 res3=10 tbres=1 -p3

🌸 Example 1: a lil floating point volume

#####################################################################
# We create a simple volume map with floating point values
#####################################################################
r3.mapcalc --o expr="volume_float = float(col() + row() + depth())"
r3.info volume_float

and r3.info says, and I quote:

 +----------------------------------------------------------------------------+
 | Layer:    volume_float                   Date: Thu Jun 14 08:40:56 2012    |
 | Mapset:   PERMANENT                      Login of Creator: soeren          |
 | Project:  TestLL                                                           |
 | DataBase: /1/soeren/grassdata                                              |
 | Title:    volume_float                                                     |
 | Units:    none                                                             |
 | Vertical unit: units                                                       |
 | Timestamp: none                                                            |
 |----------------------------------------------------------------------------|
 |                                                                            |
 |   Type of Map:  3d cell              Number of Categories: 0               |
 |   Data Type:    FCELL                                                      |
 |   Rows:         18                                                         |
 |   Columns:      36                                                         |
 |   Depths:       5                                                          |
 |   Total Cells:  3240                                                       |
 |   Total size:           10114 Bytes                                        |
 |   Number of tiles:      1                                                  |
 |   Mean tile size:       10114 Bytes                                        |
 |   Tile size in memory:  12960 Bytes                                        |
 |   Number of tiles in x, y and  z:   1, 1, 1                                |
 |   Dimension of a tile in x, y, z:   36, 18, 5                              |
 |                                                                            |
 |        Projection: Latitude-Longitude (zone 0)                             |
 |            N:        90N    S:        90S   Res:    10                     |
 |            E:       180E    W:       180W   Res:    10                     |
 |            T:          5    B:          0   Res:     1                     |
 |   Range of data:   min =          3 max =         59                       |
 |                                                                            |
 |   Data Source:                                                             |
 |                                                                            |
 |                                                                            |
 |                                                                            |
 |   Data Description:                                                        |
 |    generated by r3.mapcalc                                                 |
 |                                                                            |
 |   Comments:                                                                |
 |    r3.mapcalc expression="volume_float = float(col() + row() + depth())"   |
 |                                                                            |
 +----------------------------------------------------------------------------+

πŸ¦‹ Example 2: peek the header with ncdump

now we yeet it into a netCDF file and snoop on what came out πŸ•΅οΈβ€β™€οΈ

#####################################################################
# We use the netCDF ncdump tool to have a look at the header
# and coordinates of the exported netCDF file
#####################################################################
r3.out.netcdf --o input=volume_float output=test_float.nc
ncdump -c test_float.nc

and here's what ncdump spills:

netcdf test_float {
dimensions:
        longitude = 36 ;
        latitude = 18 ;
        z = 5 ;
variables:
        float longitude(longitude) ;
                longitude:units = "degrees_east" ;
                longitude:long_name = "Longitude values" ;
                longitude:standard_name = "longitude" ;
                longitude:axis = "X" ;
        float latitude(latitude) ;
                latitude:units = "degrees_north" ;
                latitude:long_name = "Latitude values" ;
                latitude:standard_name = "latitude" ;
                latitude:axis = "Y" ;
        float z(z) ;
                z:units = "meter" ;
                z:long_name = "z coordinate of projection" ;
                z:standard_name = "projection_z_coordinate" ;
                z:positive = "up" ;
                z:axis = "Z" ;
        float volume_float(z, latitude, longitude) ;
                volume_float:valid_min = 3.f ;
                volume_float:valid_max = 59.f ;
// global attributes:
                :Conventions = "CF-1.5" ;
                :history = "GRASS GIS netCDF export of r3.out.netcdf" ;
data:
 longitude = -175, -165, -155, -145, -135, -125, -115, -105, -95, -85, -75,
    -65, -55, -45, -35, -25, -15, -5, 5, 15, 25, 35, 45, 55, 65, 75, 85, 95,
    105, 115, 125, 135, 145, 155, 165, 175 ;
 latitude = 85, 75, 65, 55, 45, 35, 25, 15, 5, -5, -15, -25, -35, -45, -55,
    -65, -75, -85 ;
 z = 0.5, 1.5, 2.5, 3.5, 4.5 ;
}

look at those coordinates coordinate-ing 😌 the z dimension is doing its lil "projection_z_coordinate" thing and everything is very CF-1.5 coded.


πŸ‘‘ Example 3: projection settings + a null value walk in

now we add the projection-specific settings AND tell it what a null value looks like:

#####################################################################
# Exporting the projection specific settings and a null value
#####################################################################
r3.out.netcdf --o -p null=-1 input=volume_float output=test_float.nc
ncdump -c test_float.nc

and boom, a whole new char crs variable shows up with the WKT and proj4 strings, plus missing_value and _FillValue on the data variable, plus a grid_mapping link. iconique:

netcdf test_float {
dimensions:
        longitude = 36 ;
        latitude = 18 ;
        z = 5 ;
variables:
        char crs ;
                crs:crs_wkt = "GEOGCS[\"wgs84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433]]" ;
                crs:spatial_ref = "GEOGCS[\"wgs84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433]]" ;
                crs:crs_proj4 = " +proj=longlat +no_defs +a=6378137 +rf=298.257223563 +towgs84=0.000,0.000,0.000" ;
        float longitude(longitude) ;
                longitude:units = "degrees_east" ;
                longitude:long_name = "Longitude values" ;
                longitude:standard_name = "longitude" ;
                longitude:axis = "X" ;
        float latitude(latitude) ;
                latitude:units = "degrees_north" ;
                latitude:long_name = "Latitude values" ;
                latitude:standard_name = "latitude" ;
                latitude:axis = "Y" ;
        float z(z) ;
                z:units = "meter" ;
                z:long_name = "z coordinate of projection" ;
                z:standard_name = "projection_z_coordinate" ;
                z:positive = "up" ;
                z:axis = "Z" ;
        float volume_float(z, latitude, longitude) ;
                volume_float:valid_min = 3.f ;
                volume_float:valid_max = 59.f ;
                volume_float:missing_value = -1.f ;
                volume_float:_FillValue = -1.f ;
                volume_float:grid_mapping = "crs" ;
// global attributes:
                :Conventions = "CF-1.5" ;
                :history = "GRASS GIS netCDF export of r3.out.netcdf" ;
data:
 longitude = -175, -165, -155, -145, -135, -125, -115, -105, -95, -85, -75,
    -65, -55, -45, -35, -25, -15, -5, 5, 15, 25, 35, 45, 55, 65, 75, 85, 95,
    105, 115, 125, 135, 145, 155, 165, 175 ;
 latitude = 85, 75, 65, 55, 45, 35, 25, 15, 5, -5, -15, -25, -35, -45, -55,
    -65, -75, -85 ;
 z = 0.5, 1.5, 2.5, 3.5, 4.5 ;
}

πŸ’– Example 4: time as the vertical unit, absolute timestamps

bestie this one is so good. we stamp a date range on the map, tell it the vertical unit is days, and suddenly z becomes time πŸ•°οΈ

#####################################################################
# Assigning time as vertical unit and setting an absolute time stamp
#####################################################################
r3.timestamp map=volume_float date=’1 Jan 2001/5 Jan 2001’
r3.support map=volume_float vunit="days"
r3.out.netcdf --o -p null=-1 input=volume_float output=test_float.nc
ncdump -c test_float.nc

and the netCDF now has an int time(time) variable with a "gregorian" calendar and "days since 2001-01-01 00:00:00" units. the way the whole z axis just transformed ✨

netcdf test_float {
dimensions:
        longitude = 36 ;
        latitude = 18 ;
        time = 5 ;
variables:
        char crs ;
                crs:crs_wkt = "GEOGCS[\"wgs84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433]]" ;
                crs:spatial_ref = "GEOGCS[\"wgs84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433]]" ;
                crs:crs_proj4 = " +proj=longlat +no_defs +a=6378137 +rf=298.257223563 +towgs84=0.000,0.000,0.000" ;
        float longitude(longitude) ;
                longitude:units = "degrees_east" ;
                longitude:long_name = "Longitude values" ;
                longitude:standard_name = "longitude" ;
                longitude:axis = "X" ;
        float latitude(latitude) ;
                latitude:units = "degrees_north" ;
                latitude:long_name = "Latitude values" ;
                latitude:standard_name = "latitude" ;
                latitude:axis = "Y" ;
        int time(time) ;
                time:units = "days since 2001-01-01 00:00:00" ;
                time:long_name = "Time in days" ;
                time:calendar = "gregorian" ;
                time:positive = "up" ;
                time:axis = "T" ;
        float volume_float(time, latitude, longitude) ;
                volume_float:valid_min = 3.f ;
                volume_float:valid_max = 59.f ;
                volume_float:missing_value = -1.f ;
                volume_float:_FillValue = -1.f ;
                volume_float:grid_mapping = "crs" ;
// global attributes:
                :Conventions = "CF-1.5" ;
                :history = "GRASS GIS netCDF export of r3.out.netcdf" ;
data:
 longitude = -175, -165, -155, -145, -135, -125, -115, -105, -95, -85, -75,
    -65, -55, -45, -35, -25, -15, -5, 5, 15, 25, 35, 45, 55, 65, 75, 85, 95,
    105, 115, 125, 135, 145, 155, 165, 175 ;
 latitude = 85, 75, 65, 55, 45, 35, 25, 15, 5, -5, -15, -25, -35, -45, -55,
    -65, -75, -85 ;
 time = 0, 1, 2, 3, 4 ;
}

see that time = 0, 1, 2, 3, 4 ;? that's your five timestamps counted off from the start date. literally ate and left no crumbs πŸ’…


πŸ”₯ SEE ALSO πŸ”₯

  • t.rast.to.rast3
  • r3.in.ascii
  • g.region

πŸ’œ AUTHORS πŸ’œ

SΓΆren Gebbert


ok that was a LOT of netCDF and I know it, but like… look how much you just learned? you're literally a CF-1.5 girlie now. keep going, there's more 🫢

🌈 SOURCE CODE 🌈

okay bestie, you made it to the very end, and this is the part where we tell you where all this magic actually lives πŸ‘‘

  • Available at: r3.out.netcdf source code (history)
  • Accessed: Saturday Jan 17 05:41:16 2026

like, that's the exact timestamp this page got yanked up, no cap πŸ•βœ¨


and here's the lil navigation buffet, in case you wanna go explore the whole manual universe instead of just this one page πŸ¦‹

  • Main index
  • 3D raster index
  • Topics index
  • Keywords index
  • Graphical index
  • Full index

pick your fighter, they're all lowkey iconic πŸ’…


Β© 2003-2025 GRASS Development Team, GRASS GIS 8.4.2 Reference Manual

fr fr, twenty-plus years of the GRASS Development Team feeding us this good good and we're just out here thriving on it 🫢

and that's a wrap on r3.out.netcdf(1), bestie!! this whole thing came to you straight from GRASS 8.4.2, and the access stamp on it is Saturday Jan 17 05:41:16 2026 β€” so yeah, it's giving freshly-fetched, main character documentation energy πŸ‘‘πŸ’–

go forth and export those 3D rasters, you absolute legend. mwah. 😭🌸

πŸ“¦ where this page comes from