Function to write results from downscalr into NetCDF file format
Source:R/write_netcdf.R
write_netcdf.Rd
Function to write results from downscalr into NetCDF file format
Usage
write_netcdf(
res,
rasterfile,
filename = "nc_v1.nc",
raster.crs = "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0",
times = NULL,
ns = NULL,
lu.to = NULL,
value = NULL,
label = NULL,
. = NULL
)
Arguments
- res
Result from downscale
- rasterfile
RasterLayer object with ns as values
- filename
Name and path of NetCDF file
- raster.crs
CRS of raster
Examples
## A basic example to plot the observed LU changes
require(dplyr)
require(tidyr)
require(tibble)
require(ncdf4)
#> Loading required package: ncdf4
require(raster)
#> Loading required package: raster
#> Loading required package: sp
#>
#> Attaching package: ‘raster’
#> The following object is masked from ‘package:dplyr’:
#>
#> select
areas <- data.frame(ns=getValues(argentina_raster),
area=getValues(area(argentina_raster))) %>%
na.omit() %>%
group_by(ns) %>%
summarise(area=sum(area)) %>%
mutate(ns=as.character(ns))
to.plot <- argentina_luc %>%
rename("times"="Ts") %>%
left_join(areas) %>%
mutate(value=value*area) %>%
dplyr::select(-area)
#> Joining, by = "ns"
write_netcdf(to.plot ,argentina_raster, filename="H:/argentina.nc")
#> Error in R_nc4_create: Permission denied (creation mode was 4096)
#> Error in ncdf4::nc_create(filename, list(LandCover_pixshare, PixelArea)): Error in nc_create!