Create a grid inside a shapefile

Viewed 5757

I am trying to crate a grid inside a shapefile, something like this. However, I am unable to generate such grid. I was wondering if anyone has an idea on how to accomplish this.

Here is my code -

WWWL.Shape<- readOGR("E:/Juan Arango", "WWL_Commerce_OK")
WWWL.Shape
plot(WWWL.Shape)
proj4string(WWWL.Shape)

bb <- bbox(WWWL.Shape)
cs <- c(3.28084, 3.28084)*6000  # cell size 
cc <- bb[, 1] + (cs/2)  # cell offset
cd <- ceiling(diff(t(bb))/cs)  # number of cells per direction
grd <- GridTopology(cellcentre.offset=cc, cellsize=cs, cells.dim=cd)
grd
sp_grd <- SpatialGridDataFrame(grd,
                               data=data.frame(id=1:prod(cd)),
                               proj4string=CRS(proj4string(WWWL.Shape)))
plot(sp_grd)

Output of WWL.Shape

class       : SpatialPolygonsDataFrame 
features    : 1 
extent      : 334367, 334498.7, 4088915, 4089057  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=15 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0 
variables   : 1
names       : Id 
min values  :  0 
max values  :  0 
1 Answers
Related