[R] getting data associated with coordinates in a spatial data frame
Sarah Goslee
sarah.goslee at gmail.com
Thu Oct 13 20:33:00 CEST 2011
Hi,
On Thu, Oct 13, 2011 at 2:05 PM, Bailey, Daniel <bailed at spu.edu> wrote:
> Thank you Sarah. I tried your suggestion, and if I coerce it into a normal data.frame, that method works. But if you've already made the data into a SpatialPixelsDataFrame and run coordinates (both from the package "sp") so that the columns "x" and "y" become a single column "coordinates" with the format (0, 17) for x and y, how do you then call or manipulate data at a specific location?
>
> The following:
> e[e$coordinates==(0,17),]
> Doesn't work.
They "don't become a single column" but rather a single matrix with
two columns, and (0, 17) isn't the correct way to specify a vector.
You can identify particular coordinates using the form I offered
earlier, and then use that to subset the data slot of your SGPF.
Using built-in data:
library(sp)
data(meuse.grid)
m = SpatialPixelsDataFrame(points = meuse.grid[c("x", "y")], data = meuse.grid)
m at data[coordinates(m)[,"x"] == 181100 & coordinates(m)[,"y"] == 333660,]
There ought to be a more elegant way to match coordinates (other than
the do.call() and paste() approach), but I'm not sure what it is.
Sarah
--
Sarah Goslee
http://www.functionaldiversity.org
More information about the R-help
mailing list