ASCII grids as spatialgridframe
On Thu, 23 Jul 2009, Els Ducheyne wrote:
Dear all sorry to post this question, but I have been looking across multiple fora and haven't found the answer I am trying to read ascii-grids in R using the shapefile - read.asciigrid
This is not a shapefile at all.
I have found that this is of class SpatialGridDataFrame
I would like to combine this with a set of grids that are already in the
workspace but when i use the [[<-option I always get the following error
What am I doing wrong? I am not using rgdal, because of a linking error that
I cannot seem to overcome - even though the installation of rgdal and all its
dependencies didn't yield an erro
Thanks for any help!
achandata<-read.asciigrid("achan.asc")
Preferably use readGDAL() in rgdal, and note that the equivalent readAsciiGrid() in maptools allows for ESRI's locale oddities while the version in sp does not. But in general just use readGDAL().
summary(achandata)
Object of class SpatialGridDataFrame
Coordinates:
min max
coords.x1 -2.5 1002.5
coords.x2 -2.5 502.5
Is projected: NA
proj4string : [NA]
Number of points: 2
Grid attributes:
cellcentre.offset cellsize cells.dim
1 0 5 201
2 0 5 101
Data attributes:
Min. 1st Qu. Median Mean 3rd Qu. Max.
0.0000 0.0000 0.3000 0.7088 0.9000 6.2000
grids[["achan"]]<-achandata
You are trying to assign a SpatialGridDataFrame object to a column in
grids, another SpatialGridDataFrame. Why not use the cbind() method for
these objects, for example:
grids1 <- cbind(grids, achandata)
names(grids) <- c("elev", "grad", "achan")
Alternatively, but more error-prone is:
an <- names(achandata)
grids$achan <- achandata[[an[1]]]
- the name is most likely "band1", but we don't know.
Hope this helps,
Roger
Error: object is not subsettable
summary(grids)
Object of class SpatialGridDataFrame
Coordinates:
min max
coords.x1 -2.5 1002.5
coords.x2 -2.5 502.5
Is projected: NA
proj4string : [NA]
Number of points: 2
Grid attributes:
cellcentre.offset cellsize cells.dim
1 0 5 201
2 0 5 101
Data attributes:
elev grad
Min. :119.8 Min. :0.0008663
1st Qu.:140.0 1st Qu.:0.0399718
Median :144.0 Median :0.0620299
Mean :144.3 Mean :0.0821328
3rd Qu.:150.1 3rd Qu.:0.1129532
Max. :159.5 Max. :0.3284767
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: Roger.Bivand at nhh.no