title: Convert GIS shape file to raster in R?
body: <p>I need to convert shapefiles into raster format.</p>
  
  <p>I used the function "rasterize" in R package "raster", but the result does not look correct.</p>
  
  <pre><code>tst &lt;- rasterize(shpfile, r, fun="count")  
  Found 5 region(s) and 5 polygon(s)
  </code></pre>
  
  <p>There is no gird with occurrence records:</p>
  
  <pre><code>range(tst[],na.rm=TRUE)
  [1]  Inf -Inf
  Warning messages:
  1: In min(x) : no non-missing arguments to min; returning Inf
  2: In max(x) : no non-missing arguments to max; returning -Inf
  
  sum(tst[],na.rm=TRUE)
  [1] 0
  </code></pre>
  
  <p>The R script that I wrote:</p>
  
  <pre><code># download the GIS shape file
  download.file("http://esp.cr.usgs.gov/data/little/abiebrac.zip",
                destfile = "abiebrac.zip")
  
  # unzip
  unzip("abiebrac.zip")
  
  # Read shapefile into R
  library(maptools)
  
  shpfile &lt;- readShapePoly("abiebrac")
  extent(shpfile)
  
  # mapping
  plot(shpfile)
  
  library(maps)
  map("world",xlim=c(-180,-50),ylim=c(7,83),add=FALSE)
  plot(shpfile,add=TRUE,lwd=10)
  
  
  # rasterize
  library(raster)
  
  GridSize &lt;- 0.5 # degree
  r &lt;- raster(ncol= round(abs(-180-(-50))/GridSize), 
              nrow=round(abs(83-7)/GridSize))
  extent(r) &lt;- extent(c(-180, -50, 7, 83))
  tst &lt;- rasterize(shpfile, r, fun="count")
  
  # summary
  sum(tst[],na.rm=TRUE)
  range(tst[],na.rm=TRUE)
  
  # mapping
  plot(tst,col="red",main="abiebrac")  
  map("world",xlim=c(-180,-50),ylim=c(7,83),add=TRUE)
  </code></pre>