[R-sig-Geo] read ascii problem floating point
Robert J. Hijmans
r.hijmans at gmail.com
Fri Jan 21 19:20:35 CET 2011
Clémentine,
You could try something like this:
r = raster('filename.asc')
xyv <- cbind(xyFromCell(r, 1:ncell(r)), v=values(r))
write.table(xyv, file='data.txt', row.names=FALSE, sep="\t")
If xyv is correct but the file is not, perhaps the problem is caused
by confusion about the decimal delimiter (perhaps a comma on your
system?)
Robert
2011/1/21 Clémentine Fritsch <clementine.fritsch at univ-fcomte.fr>:
> Sorry for the lack of information. My purpose is to export a x,y,z text
> file.
>
> The values in the ascii imported vary from 0.4 to 5.3 while the correct
> values vary from 0.1 to 2402.
> I have performed several checking in GRASS and I really think that the
> problem is due to floating point.
>
> The values are correct using your method:
>
> r = raster('filename.asc')
> plot(r)
>
> # if you want an sp object:
> x = as(r, 'SpatialGridDataFrame')
>
> However, when I have exported a text file of x at data with "write.delim"
> {pgirmess}, the z values in the text file are incorrect (again 0.4 to 5.3
> instead of 0.1 to 2402).
>
> Ideas about how to export ?
>
> Many thanks,
>
> Clémentine
>
>
> Robert Hijmans a écrit :
>>>
>>> I have tried to read an ascii file using “readAsciiGrid” {maptools} in R
>>> 2.12.0. The z values are incorrect, and I strongly suppose that the problem
>>> is due to floating point.
>>
>> Clémentine
>>
>> If would helpful if you said what is incorrect about the z values. You
>> could
>> try this alternative route:
>>
>> library(raster)
>> r = raster('filename.asc')
>> plot(r)
>>
>> # if you want an sp object:
>> x = as(r, 'SpatialGridDataFrame')
>>
>> Robert
>>
>
> --
> Clémentine Fritsch
> PhD, post-doc researcher
> UMR 6249 - Chrono-Environment
> University of Franche-Comte
> Place Leclerc
> F-25030 Besançon Cedex
> FRANCE
> E-mail: clementine.fritsch at univ-fcomte.fr
> Tel.: +33 (0) 381 665 710
> Fax: +33 (0) 381 665 797
>
>
More information about the R-sig-Geo
mailing list