Skip to content
Prev 4472 / 29559 Next

extracting information from a raster file

We (the developers from sp) tried hard to relieve you from writing such 
code. Please try the following code, which requires you to click on the 
grid map after locator(1):

library(sp)
data(meuse.grid)
coordinates(meuse.grid)=~x+y
gridded(meuse.grid)=TRUE
fullgrid(meuse.grid) = TRUE
image(meuse.grid["dist"])
pt = locator(1)
pt
pt.sp = SpatialPoints(matrix(c(pt[[1]], pt[[2]]), 1, 2))
pt.sp
overlay(meuse.grid, pt.sp)

Besides being equally efficient, this code should remain working even if 
some internal representations of the sp classes were to change.

While looking at your code below, I have the feeling you forget that R 
arrays start with index 1, whereas C arrays start with index 0. You can 
check the sp sources to be 100% certain, but I also believe that the sp 
organization lets vary x first, then y.
--
Edzer
Harry Kim wrote: