[R] Creating a geographical grid

Michael Sumner mdsumner at gmail.com
Mon Dec 10 22:55:51 CET 2012


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:
> I would like to create a geographical grid to have a sort of a reference grid for my georeferenced survey data. The grid should be in a xy format, wgs1984 with a 0.025 degree, alternatively 10km, resolution covering -14 to -24 S and 24 to -34 E (Zimbabwe).
> Additionally I need to be able to export it as a .dbf
>
> Hope someone can help an R- novice !
>
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Michael Sumner
Hobart, Australia
e-mail: mdsumner at gmail.com




More information about the R-help mailing list