[R-sig-Geo] writeRaster to ascii file (.asc)

Robert J. Hijmans r.hijmans at gmail.com
Sat Jul 13 01:44:34 CEST 2013


I do not the data have changed. Wrong min and max values are reported,
however. Seems to me that in this case gdal does not know the min and
max values but reports  -2147483648, 2147483647. You could check with
GDALinfo. I guess that this is a  shortcoming of (your version of?)
gdal, not rgdal. Robert

On Thu, Jul 11, 2013 at 5:04 AM, Manuel Spínola <mspinola10 at gmail.com> wrote:
> Thank you Mauricio.
>
>> sessionInfo()
> R version 3.0.1 (2013-05-16)
> Platform: x86_64-apple-darwin10.8.0 (64-bit)
>
> locale:
> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
>
> attached base packages:
> [1] grid      stats     graphics  grDevices utils     datasets  methods
> base
>
> other attached packages:
> [1] SDMTools_1.1-13 dismo_0.8-11    raster_2.1-37   rgdal_0.8-10
>  maptools_0.8-25
> [6] lattice_0.20-15 sp_1.0-11       foreign_0.8-54
>
> loaded via a namespace (and not attached):
> [1] tools_3.0.1
>
>
> 2013/7/11 Mauricio Zambrano-Bigiarini <mauricio.zambrano at jrc.ec.europa.eu>
>
>> On 10/07/13 18:38, Manuel Spínola wrote:
>>
>>> Dear list members,
>>>
>>> I am trying to export a raster file to a ascii file (.asc) but the min and
>>> max values are not the same. Any idea why?
>>>
>>
>> Hi Manuel,
>>
>> Could you provide your sessionInfo() ?
>>
>>>
>>>  bio1res
>>>>
>>> class       : RasterLayer
>>> dimensions  : 382, 407, 155474  (nrow, ncol, ncell)
>>> resolution  : 0.008333333, 0.008333333  (x, y)
>>> extent      : -85.95, -82.55833, 8.041667, 11.225  (xmin, xmax, ymin,
>>> ymax)
>>> coord. ref. : NA
>>> data source : in memory
>>> names       : bio1_23
>>> values      : 47, 272  (min, max)
>>>
>>>  writeRaster(bio1res, filename="temp.asc", format="ascii",overwrite=TRUE)
>>>>
>>> class       : RasterLayer
>>> dimensions  : 382, 407, 155474  (nrow, ncol, ncell)
>>> resolution  : 0.008333333, 0.008333333  (x, y)
>>> extent      : -85.95, -82.55833, 8.041667, 11.225  (xmin, xmax, ymin,
>>> ymax)
>>> coord. ref. : NA
>>> data source : /Users/manuelspinola/Dropbox/**DistribucioÌ n de
>>>
>>> especies/World_Clim_Costa_**Rica/temp.asc
>>> names       : temp
>>> values      : -2147483648, 2147483647  (min, max)
>>>
>>
>> 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
>>
>> --
>> ==============================**===================
>> Water Resources Unit
>> Institute for Environment and Sustainability (IES)
>> Joint Research Centre (JRC), European Commission
>> TP 261, Via Enrico Fermi 2749, 21027 Ispra (VA), IT
>> Work Phone : +39 0332 789588
>> webinfo    : http://floods.jrc.ec.europa.**eu/<http://floods.jrc.ec.europa.eu/>
>> ==============================**===================
>> DISCLAIMER:
>> "The views expressed are purely those of the writer
>> and may not in any circumstances be regarded as sta-
>> ting an official position of the European Commission"
>> ==============================**===================
>> "The journey is the reward"  (Steve Jobs)
>>
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>>
>
>
> --
> *Manuel Spínola, Ph.D.*
> Instituto Internacional en Conservación y Manejo de Vida Silvestre
> Universidad Nacional
> Apartado 1350-3000
> Heredia
> COSTA RICA
> mspinola at una.ac.cr
> mspinola10 at gmail.com
> Teléfono: (506) 2277-3598
> Fax: (506) 2237-7036
> Personal website: Lobito de río <https://sites.google.com/site/lobitoderio/>
> Institutional website: ICOMVIS <http://www.icomvis.una.ac.cr/>
>
>         [[alternative HTML version deleted]]
>
>
> _______________________________________________
> 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