[R-sig-Geo] A few more questions about Adehabitat!?
Sander Oom
slist at oomvanlieshout.net
Sat Mar 26 21:58:35 CET 2005
Dear Clement,
I have made enormous progress, but I am still struggling with a couple
of things, hence the following questions:
- How can I determine the area of the polygons in an object of class
'asc'? The 'ararea' function only works on objects of class 'area', and
I can not convert 'asc' to 'area'. I would prefer a list of areas for
each polygon, which I can than total to the whole home range area.
- Would it be possible to create a function to extract the extent (x and
y limits) of an 'asc' or 'kasc' object, such that I can use the result
as an argument in the 'subsetmap' function to set xl and yl?
- Mean('asc object') returns a single value, as I was expecting, but
var('asc object') returns a matrix and sd('asc object') returns a
vector. I must be missing something! Also mean() gives NA if part of the
grid is NA. See example below!
- Is it possible to do calculations with an 'asc' object? Such as
multiplying each cell with a value? I read a grid from file and would
like to change the cell values. I would also like to change certain cell
values to NA,before doing the calculations as above. The same would be
possible if I could get the map out of the 'asc' object and put it in a
matrix of data frame.
Thanks in advance,
Sander.
Sample code for reading in an ascii grid:
> (file1 <- paste(system.file(package = "adehabitat"),
+ "ascfiles/elevation.asc", sep = "/"))
[1] "/usr/lib/R/library/adehabitat/ascfiles/elevation.asc"
> xl <- c(701000, 702000)
> yl <- c(3160000, 3161000)
>
> el <- import.asc(file1)
> image(el)
> el
Raster map of class "asc":
Cell size: 100
Number of rows: 121
Number of columns: 111
Type: numeric
> mean(el)
[1] NA
> elsub<-subsetmap(el, xlim = xl, ylim = yl)
> image(elsub)
> mean(elsub)
[1] 265.281
> rr <- lapply(el, function(x) x*1000)
> mean(rr)
[1] NA
Warning message:
argument is not numeric or logical: returning NA in: mean.default(rr)
> var(elsub)
[,1] [,2] [,3] [,4] [,5] [,6]
[,7]
[1,] 456.818182 397.1 345.58182 304.172727 298.054545 179.9727273
170.61818
[2,] 397.100000 348.6 304.80000 269.300000 262.400000 158.6000000
146.90000
[3,] 345.581818 304.8 270.01818 241.027273 235.945455 140.8272727
132.18182
[4,] 304.172727 269.3 241.02727 224.490909 219.818182 127.3909091
118.17273
[5,] 298.054545 262.4 235.94545 219.818182 217.963636 125.4181818
117.65455
[6,] 179.972727 158.6 140.82727 127.390909 125.418182 80.6909091
71.17273
[7,] 170.618182 146.9 132.18182 118.172727 117.654545 71.1727273
80.01818
[8,] 110.600000 93.6 84.10000 70.400000 69.400000 45.8000000
61.70000
[9,] 38.972727 26.8 23.52727 7.490909 7.318182 16.7909091
49.07273
[10,] -8.809091 -14.1 -10.89091 -26.536364 -26.027273 -0.6363636 38.39091
[11,] -70.254545 -73.4 -66.44545 -81.718182 -79.963636 -30.0181818 18.94545
[,8] [,9] [,10] [,11]
[1,] 110.6 38.972727 -8.8090909 -70.25455
[2,] 93.6 26.800000 -14.1000000 -73.40000
[3,] 84.1 23.527273 -10.8909091 -66.44545
[4,] 70.4 7.490909 -26.5363636 -81.71818
[5,] 69.4 7.318182 -26.0272727 -79.96364
[6,] 45.8 16.790909 -0.6363636 -30.01818
[7,] 61.7 49.072727 38.3909091 18.94545
[8,] 59.8 73.000000 75.7000000 74.10000
[9,] 73.0 136.290909 161.5636364 191.18182
[10,] 75.7 161.563636 201.8545455 242.62727
[11,] 74.1 191.181818 242.6272727 315.56364
>
--
--------------------------------------------
Dr. Sander P. Oom
Animal, Plant and Environmental Sciences,
University of the Witwatersrand
Private Bag 3, Wits 2050, South Africa
Tel (work) +27 (0)11 717 64 04
Tel (home) +27 (0)18 297 44 51
Fax +27 (0)18 299 24 64
Email sander at oomvanlieshout.net
Web www.oomvanlieshout.net/sander
More information about the R-sig-Geo
mailing list