As you said, readGDAL will give you a SpatialGridDataFrame object, which behaves much like a normal data.framet. Your best bet is to run it through names to see what data are available to work with:
names(map) Like a regular data.frame this will give you the bands or data read in from your ASCII grid, on which you can pull subsets or index like you would a normal vector (e.g. pretend your map object has "band1" as its only data, you can pull a subset of the first 10 grid values like this: map$band1[1:10] I hope that gets you closer to solving the rest of your question, Forrest Stevens Department of Geography Land Use and Environmental Change Institute University of Florida 2011/8/26 MichaÅ KwieciÅski <jamesbo...@gmail.com> > 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@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@r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > [[alternative HTML version deleted]]
_______________________________________________ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo