[R-sig-Geo] ASCII grid file - extracting data after import with readGDAL()

Michał Kwieciński jamesbond6 at gmail.com
Fri Aug 26 15:40:03 CEST 2011


Hi,

I am having difficulty in reading data for further use that is in
ASCII grid format (it's the UN population data from
http://sedac.ciesin.columbia.edu/gpw). I used readGDAL function which
leaves me with SpatialGridDataFrame class object, but apart from
creating simple image with

map = readGDAL("eur.asc", region.dim=c(889,1050), output.dim=c(889,1050))
image(map, col=topo.colors(256, alpha=1))

, I have no clue how to operate on this object. All I can see it
contains x and y coordinates, but any head() or summary() does not
provide me with information on how to refer to the actual data that
ASCII grid contains. And yet the image can be generated properly, so
the data obviously is somewhere there! I can see I theoretically
should find something under map["z"], but all I have is an error:

Error in `[.data.frame`(x at data, , i, drop = FALSE) :
  undefined columns selected



Or entire problem may be stated in terms of question: how do I set
colours for map like that (
http://sedac.ciesin.columbia.edu/gpw/maps/poldens.pdf )? (let's say I
want to manually set intervals for colouring the variable that is in
the grid file)

This is not the goal of my work with this data, but I believe the
solution do this problem has very much in common with general
operations on data from ascii grid file. Disregarding the need to
create beautiful maps, I can always try to use read.table (oh, wait,
the 5 MB bit freezes my R) and then use this data for other complex
spatial calculations that require also other data to be combined with
data from grid, but right now my problem is just as specified above.


Or maybe I should have used something else than readGDAL?


I am using R2.9.2, as any later version leaves me with blank output
instead of the image I want. Don't know the reason for it, but I
thought I will stay with the version that works instead of unnecessary
troubleshooting. I also wrote a program in C that extracted the europe
part of the world data, so that my ASCII file is 5 MB instead of 117
MB, but it appears to be OK, so I don't think the problem lies here.



More information about the R-sig-Geo mailing list