[R-sig-Geo] Extracting avg values from smoothed surface in spatstat

Marcelino de la Cruz marcelino.delacruz at upm.es
Fri Apr 25 15:19:58 CEST 2008



Hi,

Probably there is a simpler way, but in the 
meantime, you can use this experimental function 
"gridim" (of course you can modify as you want).

You have to especify the required "lag" of the 
grid (i.e. the desired length of the x-side or 
the y-side of each cell in the grid).
It gives you a list of images of the required 
size. Then use mean.im to obtain thte mean values.


Example of use:

library(spatstat)

data(longleaf)
Z <- smooth.ppp(longleaf)

plot(Z)

lapply(gridim(Z, xlag=10), mean.im)



Regards,

Marcelino








##### FUNCTION "gridim"#################################################

gridim <-  function (miim,xlag,ylag=xlag){

    xrange <- miim$xrange
    yrange <- miim$yrange

    x0 <- xrange[1]
    y0 <- yrange[1]

    maxx <- round(diff(xrange)/xlag)
    maxy <- round(diff(yrange)/ylag)

    result <- NULL
    z <- 0
    for (i in 1:maxx){
       for (j in 1:maxy){
         z <- z+1
         result[z] <- 
list(miim[owin(c((x0+xlag)*(i-1), 
(x0+xlag)*i),c((y0+ylag)*(j-1), (y0+ylag)*j))])
       }
    }

    class(result) <- c("gridedim", class(result))
    return(result)
}

###################################################################################3







At 13:26 25/04/2008, Graham Smith wrote:
>I've asked this in the general R list, but it may be better here.
>
>have used smooth.ppp in spatstat to create a smoothed surface plot
>based on randomly selected depth measurements across a lake (as marks
>in spatstat).
>
>I wonder, if based on the smoothed surface plot, if I can calculate
>the average depth for each 10x10 grid square across the lake.
>
>I can't see any obvious way of doing this and would appreciate some
>pointers.
>
>Many thanks,
>
>Graham
>
>
>
>
>
>         [[alternative HTML version deleted]]
>
>_______________________________________________
>R-sig-Geo mailing list
>R-sig-Geo at stat.math.ethz.ch
>https://stat.ethz.ch/mailman/listinfo/r-sig-geo

________________________________

Marcelino de la Cruz Rot

Departamento de  Biología Vegetal
E.U.T.I. Agrícola
Universidad Politécnica de Madrid
28040-Madrid
Tel.: 91 336 54 35
Fax: 91 336 56 56
marcelino.delacruz at upm.es




More information about the R-sig-Geo mailing list