[R] Fwd: netCDF to GeoTIFF by layer in r
Ahmed Attia
ahmedatia80 at gmail.com
Wed Mar 28 16:37:27 CEST 2018
Hi
I have a netCDF file of volumetric soil water content at four
different soil layers and want to convert each soil layer in the
netCDF file to a GeoTIFF layer. This code converts the netCDF file to
one GeoTIFF layer, i.e. unclear which soil depth.
file.nc <- "C:/Soil_Weather_data/Agro/VMC21/VMC21.nc"
file.tiff <- "C:/Soil_Weather_data/Agro /VMC21/VMC21"
importnetcdf <- raster(file.nc)
> importnetcdf
class : RasterLayer
band : 1 (of 4 bands)
#the bands here are the four soil layers
dimensions : 16800, 43200, 725760000 (nrow, ncol, ncell)
resolution : 0.00833333, 0.00833333 (x, y)
extent : -180, 179.9998, -56, 83.99995 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
data source :
C:\FAPSEP_Eucalyptus\FAPSEP\Soil_Weather_data\Agro_IBIS_Eucalipto\VMC21\VMC21.nc
names : Volumetric.water.content.at..33.kPa
z-value : 4.5
zvar : VMC2
VMC1<-writeRaster(importnetcdf,filename="file.tiff",format="GTiff",overwrite=TRUE,bylayer=TRUE,suffix="1:4")
#bylayer=TRUE, did not work.
> VMC1
class : RasterLayer
dimensions : 16800, 43200, 725760000 (nrow, ncol, ncell)
resolution : 0.00833333, 0.00833333 (x, y)
extent : -180, 179.9998, -56, 83.99995 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84
+towgs84=0,0,0
data source : C:\Users\Ahmed\Documents\file.tif
names : file
values : 2, 80 (min, max)
Any help!
Ahmed Attia, Ph.D.
Agronomist & Soil Scientist
[[alternative HTML version deleted]]
More information about the R-help
mailing list