Last active
December 14, 2015 11:08
-
-
Save xuanlongma/5076726 to your computer and use it in GitHub Desktop.
convert shapefile to raster
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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