[R-sig-Geo] Need fast method to find indices of cells in a 3-D gridthat contain (x, y, z) coor
Markus Loecher
loecher at eden.rutgers.edu
Fri Aug 17 14:37:52 CEST 2007
Thank you for this elegant method of assigning counts to cell points.
If I am not mistaken, the spatial database community uses R-trees for efficient/rapid lookup. Does anyone know of an R package which implements R-trees ?
Also, any chance the package trip might be available for Linux or the MAC in the future ?
Thanks!
Markus
------------------------------
Message: 2
Date: Fri, 17 Aug 2007 09:32:16 +1000
From: "Michael Sumner" <mdsumner at utas.edu.au>
Subject: Re: [R-sig-Geo] Need fast method to find indices of cells in
a 3-D gridthat contain (x, y, z) coordinates
To: "'Waichler, Scott R'" <Scott.Waichler at pnl.gov>,
<R-sig-geo at stat.math.ethz.ch>
Message-ID: <001501c7e05d$af155660$4627d983 at gom>
Content-Type: text/plain; charset="us-ascii"
We do a similar thing in 2D using tabulate. It assumes that the coordinates
are known not to fall outside the grid:
## xx are the x-coordinates, similarly yy
## orig is the x/y offset of the grid
## scal is the x/y width and height of grid cells
## x/ydim is the dimensions of the grid
cps <- ceiling(cbind((xx - orig[1])/scl[1], (yy - orig[2])/scl[2]))
tps <- tabulate((cps[, 1] - 1) * ydim + cps[, 2], xdim * ydim)
## then shape the counts as a matrix, appropriately aligned:
mps <- matrix(tps, ydim, xdim)
z <- t(mps)
I'm sure you could adapt this to the 3D case. That fragment comes from the
function countPoints (called by tripGrid) from the package "trip".
HTH
Mike
More information about the R-sig-Geo
mailing list