Skip to content

Instantly share code, notes, and snippets.

@xuanlongma
Last active December 14, 2015 11:08
Show Gist options
  • Save xuanlongma/5076726 to your computer and use it in GitHub Desktop.
Save xuanlongma/5076726 to your computer and use it in GitHub Desktop.
convert shapefile to raster
## Convert shapefile to raster
## Packages
require(sp)
require(raster)
## Import shapefile
shp.x = readOGR('shapefile.shp', layer = 'shapefile')
## Create an empty raster
r.x = raster(ncol = 500, nrow = 500)
## Set the spatial extent
extent(r.x) = extent(shp.x)
## Rasterize
r.x = rasterize(shp.x, r.x, 'AREA')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment