[R-sig-Geo] R-stats - GRASS6
Roger Bivand
Roger.Bivand at nhh.no
Tue May 31 18:53:31 CEST 2005
On Tue, 31 May 2005, Markus Neteler wrote:
> Dear list members,
>
> I am currently trying out the new GRASS 6/R-stats interface.
> I installed all software today (R-2.1.0, all interfaces, using
> GRASS 6.1-CVS).
>
> There is a little problem which I don't understand:
>
> > library(spgrass6)
> > G <- gmeta6()
> > str(G)
> List of 28
> $ GISDBASE : chr "/ssi0/ssi/neteler/grassdata"
> $ LOCATION_NAME : chr "spearfish60"
> $ MAPSET : chr "neteler"
> $ GRASS_DB_ENCODING: chr "utf-8"
> $ DEBUG : chr "0"
> $ MONITOR : chr "x0"
> $ GRASS_GUI : chr "text"
> $ projection : chr "1 (UTM)"
> [...]
>
> > system("r.info -t landcover.orig")
> datatype=CELL
> > landcover <- readCELL6sp("landcover.orig", cat = TRUE)
> Error in "names<-.default"(`*tmp*`, value = "landcover.orig") :
> 'names' attribute [1] must be the same length as the vector [0]
I can't replicate this, I'm afraid (R 2.1.0, Linux, sp 0.7-7, spgrass6
0.1-4 (from CVS on sourceforge, GRASS 6.0.0 release). I don't think the sp
or spgrass6 versions make a difference.
Could you say debug(readCELL6sp) and re-run this please - that should show
which line is failing. Once we know that, please check the arguments to
that function for sanity. I don't think it is important, but I'm running
under LANG=en_GB ; export LANG, not UTF8. My current guess is that the
problem is in:
res <- read.asciigrid(tmpfl, colname = vname, proj4string = p4)
where vname is the layer name. If you additionally do
debug(read.asciigrid), it may fail at: names(df) = colname - please see
what is in colname, and if length(colname) is the same as length(df). One
possibility is that there is something amiss in read.asciigrid().
The landcover.orig layer is strange because there are no category labels
at all, so:
> system("r.stats -l -q landcover.orig")
11
21
22
23
31
32
41
42
43
51
71
81
82
83
85
91
92
* no data
so the factor gets built without labels:
> str(landcover)
Formal class 'SpatialGridDataFrame' [package "sp"] with 6 slots
..@ data :Formal class 'AttributeList' [package "sp"] with 1 slots
.. .. ..@ att:List of 1
.. .. .. ..$ landcover.orig: Factor w/ 17 levels "","","","","",..: NA 15 2 2 2 2 2 2 2 2 ...
..@ grid :Formal class 'GridTopology' [package "sp"] with 3 slots
.. .. ..@ cellcentre.offset: num [1:2] 589995 4913715
.. .. ..@ cellsize : num [1:2] 30 30
.. .. ..@ cells.dim : int [1:2] 634 477
..@ grid.index : int(0)
..@ coords : num [1:2, 1:2] 589995 608985 4913715 4927995
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : NULL
.. .. ..$ : chr [1:2] "coords.x1" "coords.x2"
..@ bbox : num [1:2, 1:2] 589995 4913715 608985 4927995
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:2] "coords.x1" "coords.x2"
.. .. ..$ : chr [1:2] "min" "max"
..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slots
.. .. ..@ projargs: chr "+proj=utm +zone=13 +a=6378206.4 +rf=294.9786982 +no_defs +nadgrids=conus"
suggesting that the function should check for unique labels of the
matching number.
Best wishes,
Roger
>
> # this works:
> > landcover <- readCELL6sp("geology", cat = FALSE)
> >
>
> > lcov <- readCELL6sp("landcover.30m",cat = TRUE)
> Error in "names<-.default"(`*tmp*`, value = "landcover.30m") :
> 'names' attribute [1] must be the same length as the vector [0]
>
>
> I was inspired by
> http://r-spatial.sourceforge.net/xtra/xtra.RHnw.html
> and the upcoming article from Roger Bivand in the GRASS Newsletter Vol3.
>
> Was there a change recently which makes category transfer fail?
>
> Best regards
>
> Markus
>
>
--
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
More information about the R-sig-Geo
mailing list