I have two data frames each 1000 x 1000, one data frame (lon) with longitudes and one data frame (lat) with latitudes, specifying coordinates of a pixel (or raster) array and I'm stuck with how to combine the two data frames into one 1000 x 1000 spatialpointsdataframe (or equivalent). The first cell of the spatialpointsdataframe would have coordinates specified by lon[1,1] and lat[1,1] etc. Is there a simple way to do this? I think I can do it column by column and then binding the spatial point objects together sequentially, but this seems a bit long winded. Any ideas?
Tried as suggested:
lat.t <- data.frame(seq(10, 15, 1), seq(20, 25, 1),
seq(30, 35, 1),seq(40, 45, 1))
colnames(lat.t) <- c("1", "2", "3", "4")
lon.t <- data.frame(seq(90, 95, 1), seq(100, 105, 1),
seq(110, 115, 1), seq(120, 125, 1))
colnames(lon.t) <- c("1", "2", "3", "4")
coords <- cbind(lon = unlist(lon.t), lat= unlist(lat.t))
sp.ob <- SpatialPoints(coords)
which gives a two column sp.ob with 16 rows when I think I need a 4 x 4 so that the lon/lat match the raster.
If I do just:
coords <- cbind(lon =lon.t , lat= lat.t)
sp.ob <- SpatialPoints(coords)
I do get a 4 x 4 but with all lon in first 4 columns then all lat in last 4, and I think this doesn't give me the right lon/lat pairs if I look at the contents with:
sp.ob[1]
for example.