Message-ID: <CAM_vjunxiJRegVD6Up0b4AdEMLgDZqqVu7keGCQ_oUNO_9wTSA@mail.gmail.com>
Date: 2011-10-13T18:33:00Z
From: Sarah Goslee
Subject: getting data associated with coordinates in a spatial data frame
In-Reply-To: <CB48FBE34FD7F64D8FFDBB410C26CF750138C72B8DFA@EXCH07-VS1.spu.local>
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