[R-sig-Geo] decimals in NA value using raster::writeRaster with .ascii format
Zack Holden
zaholdenfs at gmail.com
Thu Apr 10 22:06:58 CEST 2014
Dear list,
I am creating ascii files as inputs to the PCraster software (no other
gdal format is allowed). When I write my ascii file using
raster::writeRaster, the first cell of every raster that I write has a
large number of decimal values appended to it. This causes errors
later in the model workflow.
This also happens to the first NA value in the file, so that all NA
values in the file are e.g. -9999 except the first cell. which appears
as: -9999.00000000000
Can anyone suggest a method for ensuring that all of my NA values are
identical and with no trailing decimals?
A small reproducible example follows. Any help or suggestions is appreciated.
Thanks,
Zack
##################
# start code
require(raster)
r <- raster(nrows=2, ncols=2, xmn=0, xmx=2, ymn=0, ymx=2)
r <- setValues(r, seq(1:ncell(r)))
rexpand <- extend(r, c(2,2))
NAvalue(rexpand) <- -9999
temp.dir <- "/home/zholden/"
writeRaster(rexpand, file=paste(temp.dir, "testraster.asc",sep=""),
NAflag=-9999, dataType="INT2U", overwrite=T)
# end code
##################
# opening in a text editor reveals trailing decimals in the first NA value.
system(paste("gedit ", temp.dir, "testraster.asc", sep=""))
################################
sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-redhat-linux-gnu (64-bit)
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
LC_MONETARY=en_US.UTF-8
[6] LC_MESSAGES=en_US.UTF-8 LC_PAPER=en_US.UTF-8 LC_NAME=C
LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] rgdal_0.8-16 raster_2.2-12 sp_1.0-14
loaded via a namespace (and not attached):
[1] grid_3.0.2 lattice_0.20-23 tools_3.0.2
More information about the R-sig-Geo
mailing list