Debian Codegraph @

R/surfaceArea.R

raw
1 surfaceArea.matrix <- function(m,cellx=1,celly=1,byCell=FALSE){
2
3 if(byCell){
4 mout = matrix(NA,nrow=nrow(m),ncol=ncol(m))
5 }else{
6 mout = NA
7 }
8
9 m=cbind(m[,1],m,m[,ncol(m)])
10 m=rbind(m[1,],m,m[nrow(m),])
11 storage.mode(m) <- "double"
12
13 ret = .C("sarea",
14 m,
15 as.integer(nrow(m)),
16 as.integer(ncol(m)),
17 as.double(cellx),
18 as.double(celly),
19 sa=as.double(mout),
20 bycell=as.integer(byCell),
21 NAOK=TRUE)
22 if(!byCell){
23 return(ret$sa)
24 }else{
25 return(matrix(ret$sa,ncol=ncol(mout),nrow=nrow(mout)))
26 }
27 }
28 setMethod("surfaceArea", signature("matrix"), surfaceArea.matrix)
29
30 surfaceArea.SpatialGridDataFrame <- function(m,cellx=1,celly=1,byCell=FALSE){
31 cs = gridparameters(m)$cellsize
32 ret = surfaceArea(as.matrix(m), cs[1], cs[2], byCell = byCell)
33 if (is.matrix(ret)) {
34 m[[1]] = as.vector(ret)
35 m
36 } else
37 ret
38 }
39 setMethod("surfaceArea", signature("SpatialGridDataFrame"),
40 surfaceArea.SpatialGridDataFrame)
41
42 surfaceArea.SpatialPixelsDataFrame <- function(m, byCell=FALSE)
43 surfaceArea(as(m, "SpatialGridDataFrame"), byCell = byCell)
44 setMethod("surfaceArea", signature("SpatialPixelsDataFrame"),
45 surfaceArea.SpatialPixelsDataFrame)