Skip to content
Prev 5950 / 29559 Next

col,row coordinates from utmx,utmy coordinates

On Fri, 19 Jun 2009, Agustin Lobo wrote:

            
Try this:

library(sp)
getRowCol <- function(SG, pts) {
  o <- overlay(SG, pts)
  cd <- slot(slot(SG, "grid"), "cells.dim")
  cols <- o %% cd[1]
  rows <- cd[2] - o %/% cd[1]
  list(cols=cols, rows=rows)
}
GT <- GridTopology(c(1,1), c(1,1), c(20000, 10000))
SG <- SpatialGrid(GT)
pts <- spsample(SG, n=20, type="random")
pts
getRowCol(SG, pts)

which just depends on the definition of the raster. Watch the row numbers 
- here they follow the coordinates (lowest number at south), but maybe 
ought to have lowest number at north. This is not memory intensive.

Hope this helps,

Roger