I have a Landsat image with 11 bands. I need to run k means classification in R. But I do not need the whole of the image as my study area is much smaller. So I have created shapefile of the Region of Interest (ROI) in ArcGIS which specifically covers my study area.

How does one clip a raster image to the extent of a shapefile (here my ROI) in R?

  • 1
    Welcome to GIS SE. Please refine your post into a single, focused question. It would also be helpful to include any code you have created. – Aaron Jan 3 at 16:21
  • 1
    with the mask function, check this: gis.stackexchange.com/questions/61243/clipping-a-raster-in-r – Ariel Jan 3 at 18:21
  • If you do not have an irregular area you can use raster::crop along with raster::extent to define the bounding box. This is much faster than raster::mask and would look something like: crop(x, extent(-160, 10, 30, 60) ) The arguments for raster::extent are: xmin, xmax, ymin, ymax defining the corners of the bounding extent. – Jeffrey Evans Feb 20 at 21:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.