Skip to content

Creating a geographical grid

2 messages · Ulrik Bo Pedersen, Michael Sumner

#
You can do this with basic R functions:

## create vectors of the longitude and latitude values
x <- seq(from = 24, to = 34, by = 0.025)
y <- seq(from = -24, to = -14, by = 0.025)

## create a grid of all pairs of coordinates (as a data.frame)
xy <- expand.grid(x = x, y = y)

## load the "foreign" package to write to DBF
library(foreign)
write.dbf(xy, file = "xy.dbf")

Note that there's nothing particularly "geographical" about any of
this, and using "10km resolution" with longitude / latitude
coordinates could only be done with an approximation that was not
constant over the area, unless you used an appropriate map projection
(i.e. not long/lat). Note that a 0.025 long/lat spacing is more like
2.7 km in this region (and it changes within the region)  so you might
need to check why you have that number.

Also, the coordinates created above are only "WGS84" by virtue of the
fact that you state that they are, there's no way to store that
metadata in DBF. If you need to explore this further the R-Sig-Geo
mailing list is appropriate  for spatial functions and formats.

Cheers, Mike.
On Mon, Dec 10, 2012 at 10:08 PM, Ulrik Bo Pedersen <ubop at sund.ku.dk> wrote: