Skip to content
Prev 274438 / 398506 Next

getting data associated with coordinates in a spatial data frame

On 13-Oct-11 20:33, Sarah Goslee wrote:
Not sure if it is nicer, but another possibility is:
data(meuse.grid)
coordinates(meuse.grid) = ~x+y
meuse.grid at data[which(duplicated(rbind(c(181100, 333660), 
coordinates(meuse.grid))))-1,]  = factor(c(1,2,3,4,1))

To avoid numerical problems, you can also find the data of the location 
closest to the point you are interested in:
meuse.grid at data[which.min(spDistsN1(meuse.grid, c(181100, 333660))),] = 
factor(c(1,1,1,1,1))

For questions about spatial data you can also use the mailing-list 
r-sig-geo.

Cheers,
Jon