I want to clip a raster using shapefile in r as a shape of shapefile. I used crop function but it clipping as extents not as a shape. Please help me
1 Answers
4
votes
Crop, as stated in the manual pages, crops to the extent of the object,
for your purposes you may use raster::mask()
, with the same syntaxis of crop
mask function "Creates a new Raster* object that has the same values as x, except for the cells that are NA (or other maskvalue) in a ’mask’."
You may pass inverse=T
so you get those values out of the spatialPolygon.