Skip to content
Back to formatted view

Raw Message

Message-ID: <44160B40.4050304@utas.edu.au>
Date: 2006-03-14T00:16:00Z
From: Michael Sumner
Subject: SpatialGrid from matrix
In-Reply-To: <20060313150836.1940wfo6tuaoog48@agenda.dpi.inpe.br>

> require(splancs)
> data(bodmin)
> x= kernel2d(as.points(bodmin), bodmin$poly, h0=2, nx=100, ny=100)
> require(sp)
> g=expand.grid(x$x,x$y,x$z)
>
> The last line gives the following error:
> Error: cannot allocate vector of size 390625 Kb
>   

You are expanding your grid for every cell in the matrix, per every grid 
location - which *really is* a lot of memory.  You really want something 
like this:

g <- cbind(expand.grid(x = x$x, y = x$y), as.vector(x$z))
coordinates(g) <- c("x", "y")
gridded(g) <- TRUE
image(g)
contour(x, add = T)  ## just to be sure

I'm pretty sure the ordering is right for this case, but be sure to check.

Cheers, Mike.