'How to find which grid cell my point is in using R?
Similar questions have been asked before, but they are either for some complicated raster mapping or are for Python. I am trying to find the minimum values of a grid cell which a given point is in. For example, if I have a grid that looks like the one below:
My point is in grid cell -7.3, 55.3. That is, these are the minimal values needed to tell me which grid cell my point is in.
So, if I have some data that looks like this:
lo <- -c(7, 7.1, 7.2, 7.3, 7.4, 7.5, 7.6, 7.7, 7.8, 7.9, 8.0)
la <- c(55, 55.1, 55.2, 55.3, 55.4, 55.5)
df <- data.frame(long = c(lo, lo, lo, lo, lo, lo),
lat = c(rep(55,11), rep(55.1,11), rep(55.2,11), rep(55.3,11), rep(55.4,11), rep(55.5,11))
)
myPoint = c(-7.24, 55.36)
Here, df defines my grid and myPoint is the point that im trying to find the grid reference of.
I was trying something like this to solve it:
df[which.min(abs(myPoint[1]-df$long)),][1]
df[which.min(abs(myPoint[2]-df$lat )),][2]
but this gives me the closest grid values. Im looking for the minimum grid values.
Any suggestion as to how I could do this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

