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

Alexander Arpaci alexander.arpaci at boku.ac.at
Fri Aug 26 15:49:11 CEST 2011

I use the raster package for asci files 
it works great and has a very hands on access to get statistics or do
any kind of raster operations

MSc. Alexander Arpaci
Assistant researcher

Department of Forest - and Soil Sciences
Institute of Silviculture
Tel. +43-1-47654-4081
e-mail: alexander.arpaci at boku.ac.at
>>> Micha* Kwieci*ski 26.08.11 15.41 Uhr >>>

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),
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.

R-sig-Geo mailing list
R-sig-Geo at r-project.org

More information about the R-sig-Geo mailing list