Skip to content
Prev 10933 / 29559 Next

How to draw grid contours within a map

Hi Thiago,

It seems to work just fine with geographic coordinates as well.  I am
working at the moment with a GCS WGS84 shape of Africa (af.gsc), and
the following seems to work fine:

# Africa shapefile download from
# http://www.internationalmapping.com/index/Goodies_Africa.html

p.base <- "/path/to/Africa.shp
setwd(p.base)

gcs.proj <- "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0"

af <- readOGR(dsn = "African_Coastline.shp", layer = "African_Coastline")
af.gsc <- spTransform(af, gcs.proj)  # Transform it GSC

ex <- bbox(af.gsc)

# 10 degree grid
gr <- createPolyGrid(x = ex[1, 1], y = ex[2, 1], h = ex[2, 2] - ex[2,
1], w = ex[1, 2] - ex[1, 1], size = 10)

plot(af.gsc)
plot(gr, add = T)

You might want to check the accuracy of the grids (caveat emptor), or
perhaps a wiser person than myself can comment on the soundness of
this approach.

Cheers, Lyndon
On Tue, Feb 15, 2011 at 11:31 AM, Thiago Veloso <thi_veloso at yahoo.com.br> wrote: