jmutua
jmutua

Reputation: 293

How to loop through many rasters in a folder and extract values using a point shapefile

How do I loop through all rasters (TIFF) in a folder and extract values using a point shapefile which has several coordinates then have the output as a dataframe?

Upvotes: 3

Views: 1979

Answers (1)

Geo-sp
Geo-sp

Reputation: 1704

library(raster)
library(rgdal)

files <- list.files(path=".", pattern="tif$", full.names=TRUE) # select all the tiff files in the directory
s <- stack(files) # stack all of them using r raster library
shp <- shapefile("points.shp") # read the point shape file
ext <- extract(s, shp) # extract the values from raster stack.

Upvotes: 4

Related Questions