title: Extracting multiple .tiff files using a Shapefile
body: <p>I have a folder named Mar22_073685 with 1372 tiff image . I need to crop these tiff files using a shapefile in another folder named 'Export_Output_2_Project.shp'. I am cropping these tiff files with the help of loop but when I am opening the output files there is no data in those files. It is blank. Also, the files are not saved with the same name as the input.</p>
  <p>I tried:</p>
  <pre><code>require(rgeos)
  require(sp)
  require(sf)
  require(maptools)
  require(raster)
  require(rgdal)
  Shape &lt;- readOGR(&quot;F:/NSSS_2019/Export_Output_2_Project.shp&quot;)
  plot(Shape)
  flname1 &lt;- list.files(path = 'F:/FOG_ISLANDS/DEC_2015/Mar22_073685/', pattern = '.tif',full.names=TRUE)
  nfile1 &lt;- length(flname1)
  for (i in 1:nfile1) {
  r1 &lt;- raster(flname1[i])
  cropimage &lt;- mask(r1, Shape)
  writeRaster(cropimage, paste0('F:/FOG_ISLANDS/DEC_2015/test/', flname1[i], '.tiff', sep = ''), format = 'GTiff', overwrite = T) 
  }
  </code></pre>