Skip to content
Prev 18789 / 29559 Next

writeRaster to ascii file (.asc)

On 10/07/13 18:38, Manuel Sp?nola wrote:
Hi Manuel,

Could you provide your sessionInfo() ?
Unfortunately, your example is not reproducible, so I tried with a 
different example and the values in the original and the written ascii 
file were the same (rgdal_0.8-10, raster_2.1-48, sp_1.0-11):

----------  START --------------
library(raster)
Loading required package: sp

# Creation of a raster file for testing
r <- raster(system.file("external/test.grd", package="raster"))

r
#class       : RasterLayer
#dimensions  : 115, 80, 9200  (nrow, ncol, ncell)
#resolution  : 40, 40  (x, y)
#extent      : 178400, 181600, 329400, 334000  (xmin, xmax, ymin, ymax)
#coord. ref. : +init=epsg:28992 
+towgs84=565.237,50.0087,465.658,-0.406857,0.350733,-1.87035,4.0812 
+proj=sterea +lat_0=52.15616055555555 +lon_0=5.38763888888889 
+k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +units=m +no_defs
#data source : /usr/lib64/R/library/raster/external/test.grd
#names       : test
#values      : 128.434, 1805.78  (min, max)

writeRaster(r, filename="temp.asc", format="ascii",overwrite=TRUE)
#rgdal: version: 0.8-10, (SVN revision 478)
#Geospatial Data Abstraction Library extensions to R successfully loaded
#Loaded GDAL runtime: GDAL 1.9.2, released 2012/10/08
#Path to GDAL shared files: /usr/share/gdal
#Loaded PROJ.4 runtime: Rel. 4.8.0, 6 March 2012, [PJ_VERSION: 480]
#Path to PROJ.4 shared files: (autodetected)
#class       : RasterLayer
#dimensions  : 115, 80, 9200  (nrow, ncol, ncell)
#resolution  : 40, 40  (x, y)
#extent      : 178400, 181600, 329400, 334000  (xmin, xmax, ymin, ymax)
#coord. ref. : NA
#data source : /home/zambrhe/temp.asc
#names       : temp

# reading the .asc file form disk
r2 <- raster("temp.asc")

r2
#class       : RasterLayer
#dimensions  : 115, 80, 9200  (nrow, ncol, ncell)
#resolution  : 40, 40  (x, y)
#extent      : 178400, 181600, 329400, 334000  (xmin, xmax, ymin, ymax)
#coord. ref. : NA
#data source : /home/zambrhe/temp.asc
#names       : temp

# Summary of the ascii file in the hard disk
#summary(r2)
#             temp
#Min.     128.4340
#1st Qu.  293.2325
#Median   371.4120
#3rd Qu.  499.8195
#Max.    1805.7800
#NA's    6097.0000


# Summary of the original raster file
summary(r)
#             test
#Min.     128.4340
#1st Qu.  293.2325
#Median   371.4120
#3rd Qu.  499.8195
#Max.    1805.7800
#NA's    6097.0000
----------  END --------------

Kind regards,

Mauricio Zambrano-Bigiarini, Ph.D