Dear Prof. Robert J. Hijmans,

I hope this can help. Probaly the problem is the "setMinMax(rt)" before
save ascii file, but when i write TIF there is the following message

rt <- writeRaster(r.mean, filename="DEM_Heigh.tif", format="GTiff",
overwrite=TRUE, NAflag=-9999)
> readLines('DEM_Heigh.tif', 6)[6]
[1] NA
[1] NA
Warning message:
In readLines("DEM_Heigh.tif", 6) :
  incomplete final line found on 'DEM_Heigh.tif'


########### start session


> library(raster)
> library(rgdal)
> ground  <- read.delim("ground.txt", sep=",",header=TRUE)
> coordinates(ground) =~X+Y
>
> r = raster(extent(ground))
> res(r) = 0.5
> r.mean <- rasterize(ground, r, 'Z', fun=mean)
>
>
> rt <- writeRaster(r.mean, filename="DEM_Heigh.tif", format="GTiff",
overwrite=TRUE, NAflag=-9999)
> readLines('DEM_Heigh.tif', 6)[6]
[1] NA
Warning message:
In readLines("DEM_Heigh.tif", 6) :
  incomplete final line found on 'DEM_Heigh.tif'
> rt
class       : RasterLayer
dimensions  : 1659, 2810, 4661790  (nrow, ncol, ncell)
resolution  : 0.5, 0.5  (x, y)
extent      : 267586.6, 268991.6, 4147061, 4147890  (xmin, xmax, ymin, ymax)
projection  : NA
values      : C:/DEM_Heigh.tif
min value   : 1332.69
max value   : 1744.35

> rt = setMinMax(rt)
> rt
class       : RasterLayer
dimensions  : 1659, 2810, 4661790  (nrow, ncol, ncell)
resolution  : 0.5, 0.5  (x, y)
extent      : 267586.6, 268991.6, 4147061, 4147890  (xmin, xmax, ymin, ymax)
projection  : NA
values      : C:/DEM_Heigh.tif
min value   : 1332.69
max value   : 1744.35

>
>
> rt <- writeRaster (r.mean, "DEM_Heigh.asc", format="ascii", overwrite=T,
datatype="INT4S",NAflag=-9999)
> readLines('DEM_Heigh.asc', 6)[6]
[1] "NODATA_value -9999 "
> rt
class       : RasterLayer
dimensions  : 1659, 2810, 4661790  (nrow, ncol, ncell)
resolution  : 0.5, 0.5  (x, y)
extent      : 267586.6, 268991.6, 4147061, 4147890  (xmin, xmax, ymin, ymax)
projection  : NA
values      : C:/DEM_Heigh.asc
min value   : -3
max value   : 1744

> rt = setMinMax(rt)
> rt
class       : RasterLayer
dimensions  : 1659, 2810, 4661790  (nrow, ncol, ncell)
resolution  : 0.5, 0.5  (x, y)
extent      : 267586.6, 268991.6, 4147061, 4147890  (xmin, xmax, ymin, ymax)
projection  : NA
values      : C:/DEM_Heigh.asc
min value   : 1333
max value   : 1744


> sessionInfo()
R version 2.11.1 (2010-05-31)
i386-pc-mingw32

locale:
[1] LC_COLLATE=Italian_Italy.1252  LC_CTYPE=Italian_Italy.1252
LC_MONETARY=Italian_Italy.1252
[4] LC_NUMERIC=C                   LC_TIME=Italian_Italy.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] spatstat_1.21-5 deldir_0.0-13   mgcv_1.6-2      raster_1.8-12
rgdal_0.6-29    maptools_0.7-38
[7] lattice_0.18-8  sp_0.9-76       foreign_0.8-40

loaded via a namespace (and not attached):
[1] grid_2.11.1        Matrix_0.999375-39 nlme_3.1-96

	[[alternative HTML version deleted]]

