col,row coordinates from utmx,utmy coordinates
On Fri, 19 Jun 2009, Agustin Lobo wrote:
Hi! Given a jpg + jpgw files I would like to get the col,row coordinates of the jpg file that correspond to a set of projected utmx, utmy coordinates, best not having to import the jpg file into R because of its size.
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
Does this exist within R (in raster package or any other)? Or should I use spgrass and/or rsaga? Thanks Agus
Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: Roger.Bivand at nhh.no