1 year ago

#334869

test-img

shravani banerjee

Extracting multiple .tiff files using a Shapefile

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.

I tried:

require(rgeos)
require(sp)
require(sf)
require(maptools)
require(raster)
require(rgdal)
Shape <- readOGR("F:/NSSS_2019/Export_Output_2_Project.shp")
plot(Shape)
flname1 <- list.files(path = 'F:/FOG_ISLANDS/DEC_2015/Mar22_073685/', pattern = '.tif',full.names=TRUE)
nfile1 <- length(flname1)
for (i in 1:nfile1) {
r1 <- raster(flname1[i])
cropimage <- mask(r1, Shape)
writeRaster(cropimage, paste0('F:/FOG_ISLANDS/DEC_2015/test/', flname1[i], '.tiff', sep = ''), format = 'GTiff', overwrite = T) 
}

r

crop

mask

tiff

geotiff

0 Answers

Your Answer

Accepted video resources