Satya Chandra
Satya Chandra

Reputation: 758

Clipping of raster as a shapefile in r

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

Upvotes: 0

Views: 1572

Answers (1)

Elio Diaz
Elio Diaz

Reputation: 600

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.

Upvotes: 4

Related Questions