[R-sig-Geo] Issue saving ascii with writeRaster function
Robert J. Hijmans
r.hijmans at gmail.com
Sat Aug 30 23:37:30 CEST 2014
Damien,
The default setting is to write Real numbers, hence the
1.000000000000000 (which is needed to trick GDAL and ESRI to not
assume that the values are all integers when the first numbers have no
decimals).
If you want integers, you can do
writeRaster(r, filename = "test.asc", datatype='INT4S')
> cat(readLines("test.asc"), sep="\n")
NCOLS 2
NROWS 2
XLLCORNER -100
YLLCORNER -100
CELLSIZE 100
NODATA_value -9999
1 1
1 1
Best, Robert
On Thu, Jul 24, 2014 at 11:51 PM, Damien GEORGES
<damien.georges2 at gmail.com> wrote:
> Dear all,
>
> When I try to write a raster as .asc file on my HD using writeRaster
> function. When I check then the .asc file produce with a text editor, the
> first item on my raster is always stored under a strange format (e.g adding
> lot of decimals). That cause then some trouble in other software using this
> maps as input..
>
> Here a (reproducible example) :
>
> ##########
>
> library(raster)
>
> ## create raster
> r <- raster(ncols=2,nrows=2,xmn=-100,ymn=-100,xmx=100,ymx=100)
> r[] <- 1
> # plot(r)
>
> ## save the raster in acii format
> writeRaster(r, filename = "test.asc")
>
> ## check .asc file content
> cat(readLines("test.asc"), sep="\n")
>
> ## output :
> # NCOLS 2
> # NROWS 2
> # XLLCORNER -100
> # YLLCORNER -100
> # CELLSIZE 100
> # NODATA_value -9999
> # 1.000000000000000 1
> # 1 1
>
> ## The first value is 1.00000000000 and I want it to be 1
>
> ##########
>
> Does someone has already experiment this kind of issue?
> Any suggestion to prevent from it?
>
> Best,
> Damien.
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
More information about the R-sig-Geo
mailing list